How to upload a file with uploadify?

1,057 views
Skip to first unread message

uonick

unread,
Jan 24, 2013, 9:54:36 AM1/24/13
to f3-fra...@googlegroups.com
Hi again :D
i use uploadify javascript plugin and trying accept a file from $_FILES['Filedata']['tmp_name']:

$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $f3->get('UPLOADS');
$targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name'];
move_uploaded_file($tempFile,$targetFile);

but I get an error 500 =(


PS:

$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $f3->get('UPLOADS');
$targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name'];
//move_uploaded_file($tempFile,$targetFile);
print_r($tempFile . ' => ' .$targetFile);



I get this:

but the picture in the folder not found

/PPS: sry 4 my bad eng ;(
thnx

ikkez

unread,
Jan 24, 2013, 10:29:32 AM1/24/13
to f3-fra...@googlegroups.com
it is so much easier ;)

use the F3 Web Class... like \Web::instance()->receive();

that's all for the basic usage.. otherwise look into this one:

https://github.com/bcosca/fatfree/blob/master/lib/web.php#L128

uonick

unread,
Jan 24, 2013, 11:25:46 AM1/24/13
to f3-fra...@googlegroups.com

it is so much easier ;)

use the F3 Web Class... like \Web::instance()->receive();

that's all for the basic usage.. otherwise look into this one:

https://github.com/bcosca/fatfree/blob/master/lib/web.php#L128

Now error 404 :( 

uonick

unread,
Jan 24, 2013, 12:39:11 PM1/24/13
to f3-fra...@googlegroups.com
I think this method can not accept the file
but this method work:
if (file_exists($_FILES['Filedata']['tmp_name'])) {
echo "Temp file exists";
}
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetFile = $_SERVER['DOCUMENT_ROOT'] . '/uploads/img/'. $_FILES['Filedata']['name'];

move_uploaded_file($tempFile,$targetFile);
if (file_exists($targetFile)) {
echo "Uploaded file exists";
}


uonick

unread,
Jan 24, 2013, 1:24:19 PM1/24/13
to f3-fra...@googlegroups.com
but would like to do it by means of Fat-Free

ikkez

unread,
Jan 24, 2013, 5:54:06 PM1/24/13
to f3-fra...@googlegroups.com
Okay, i tried it by myself to get this uploader working.

i downloaded the free version of uploadify and put all contents into /ui/uploadify

My Routes:
 
$f3->route('GET /upload', function($f3){
    $f3->set('timestamp',time());
    echo Template::instance()->render('uploadify/index.html');
});
 
$f3->route('POST /upload', function($f3){   
    $f3->set('UPLOADS','data/');   
    \Web::instance()->receive(null,false,false);   
});

Notice: set the slug argument of receive to false (the 3rd one)...it seems that here is a bug,.. i always get error 500, undefined offset 2 when $slug is true.

i renamed the uploadify/index.php to .html and changed a bit:
http://534f.de/k4NJPCG6/html

and now another thing: the flash upload does not send the right file mime type... F3 checks the mimetype (i dont know why exactly) but because of that, the upload fails everytime.. 
you can go to this line: https://github.com/bcosca/fatfree/blob/dev/lib/web.php#L157 and remove / comment it
it should work then.

on the other hand, a flash upload might not be the best choice.... maybe you can have a look to another HTML5 Uploader like http://blueimp.github.com/jQuery-File-Upload/
getting started with it is also pretty easy...

so long.. regards.


uonick

unread,
Jan 24, 2013, 10:43:14 PM1/24/13
to f3-fra...@googlegroups.com
Thank you very much for taking the time! 
I will try to use HTML5 uploader (especially as it fits perfectly into the design)

uonick

unread,
Jan 26, 2013, 12:44:59 AM1/26/13
to f3-fra...@googlegroups.com
I tried a few options but my version only worked...
uploadify:

php:

my routes placed in config.php:
[routes]
;General routes
POST|PUT /gallery/upload=gallery->add_photos


if i use html5 uploader i get an errors (404 or 500)
404 because route not found
500 because.... i have no idea :(
in javascript console i see error: 500

if i use print_r($_FILES) i get this:

(and this is true)


but if i use \Web::instance()->receive(null,false,false);  method or Web::instance()->receive() i allways get an error 500...
and temp file not found....



uonick

unread,
Jan 26, 2013, 2:01:24 AM1/26/13
to f3-fra...@googlegroups.com
and...

<form action="/gallery/upload" method="post" enctype="multipart/form-data">        
<input type="file" multiple="multiple" name="file[]" id="file" />
 <input name="submit" type="submit" value="Submit" />    
</form>


...

foreach($_FILES as $file){      
        echo '<pre>';
        print_r($file);
        echo '</pre>';
    }



but:

foreach($_FILES as $file){      
        echo '<pre>';
        print_r($file[tmp_name]);
        echo '</pre>';
    }

i get error:

Internal Server Error

Fatal error: Maximum function nesting level of '100' reached, aborting!

in /lib/base.php:431

ikkez

unread,
Jan 26, 2013, 10:58:24 AM1/26/13
to f3-fra...@googlegroups.com
try removing the mime-type check in Web::receive again...
a .jpg file should be send with a type of "image/jpeg" and not "application/octet-stream"

when you get error404, check if your route is really correct... do you run F3 from a subdirectory? if true, have you set a <base>-TAG in your html template? this is important.

uonick

unread,
Jan 27, 2013, 2:26:41 AM1/27/13
to f3-fra...@googlegroups.com
worked version for me:

HTML5 form:
(without a  enctype="multipart/form-data" do not work)

in PHP method:

ty...

uonick

unread,
Jan 27, 2013, 5:26:05 AM1/27/13
to f3-fra...@googlegroups.com
Now, how to get filename from \Web  ?

bcosca

unread,
Jan 27, 2013, 6:17:44 AM1/27/13
to f3-fra...@googlegroups.com
First arg of receive() is a callback function with the upload file details as arg.

uonick

unread,
Jan 27, 2013, 7:16:49 AM1/27/13
to f3-fra...@googlegroups.com
a small example?
I knew the name of the file gets to the variable $file?

uonick

unread,
Jan 29, 2013, 4:21:26 AM1/29/13
to f3-fra...@googlegroups.com
may be a small example?

воскресенье, 27 января 2013 г., 17:17:44 UTC+6 пользователь bcosca написал:

uonick

unread,
Jan 30, 2013, 2:20:25 PM1/30/13
to f3-fra...@googlegroups.com
http://pastebin.com/3rxN89w5

Error:

Internal Server Error

Fatal error: Maximum function nesting level of '100' reached, aborting!

/lib/base.php:432 


but if code is:
http://pastebin.com/aqYErQ0r

i get http://pastebin.com/FqHa7w1e

=(

ikkez

unread,
Jan 30, 2013, 6:13:56 PM1/30/13
to f3-fra...@googlegroups.com
it's not
$web->receive(function() use($web) {
but
$web->receive(function($file) {


and then use $file[name][0] to get the first filename.

uonick

unread,
Jan 30, 2013, 10:29:23 PM1/30/13
to f3-fra...@googlegroups.com


getting error:

Internal Server Error

Fatal error: Maximum function nesting level of '100' reached, aborting! 

=(

bcosca

unread,
Jan 30, 2013, 11:52:07 PM1/30/13
to f3-fra...@googlegroups.com
This may be caused by something else in your program. Grab the 3.0.4 version. It has better error reporting. And try to use die() frequently in your program while you're testing. It's good for isolating your problems.

uonick

unread,
Jan 31, 2013, 12:24:47 AM1/31/13
to f3-fra...@googlegroups.com

uonick

unread,
Jan 31, 2013, 12:25:16 AM1/31/13
to f3-fra...@googlegroups.com
Current version 3.0.4...

bcosca

unread,
Jan 31, 2013, 8:09:56 AM1/31/13
to f3-fra...@googlegroups.com
This is so easy to debug that telling you outright what the problem is would be spoon-feeding you on how to write programs.

Instead of:
die($file[name][0]);

Have you tried:
var_dump($file);

Reply all
Reply to author
Forward
0 new messages