Uploadify and PHP FTP - $_REQUEST['folder'] not getting passed
I am trying to use uploadify and an FTP connection to upload a file. I realized the directories weren't being created because the 'folder' var from the js is not getting passed. I am wondering if this is a scope thing. Anyway, here is the js:
$("#uploadify").uploadify({
'uploader' : '/lib/jquery.uploadify-v2.1.0/uploadify.swf',
'script' : '/lib/jquery.uploadify-v2.1.0/uploadify.php',
'cancelImg' : '/lib/jquery.uploadify-v2.1.0/example/cancel.png',
'folder' : '<?=time()?>',
'queueID' : 'fileQueue',
'multi' : true
});
PHP:
$dir = $_REQUEST['folder'];
if (!ftp_mkdir($conn_id, $dir)) {
echo "There was a problem while creating $dir\n";
} else {
echo "successfully created $dir\n";
}
I get an error-- "ftp_mkdir(): Unab开发者_JAVA技巧le to create the directory."
I did check to see if the time() was getting echoed out and it is. If I hardcode a plain string there it fails. But if I change the $dir to equal "whatever" (rather than request) the directory will get created, but it will not take the request param. I tried get and post as well.
Also this same scenario does work if I am not using FTP, just upload to server the page is being served from – no problems.
Two things you can do to diagnose:
- Make sure that PHP is accessing the path you think it is accessing.
- Make sure that
send-files
exists in that path and that it is world writable.
From your error message it looks like you're perhaps running your server on a Linux or Mac box (I'm guessing Mac). Do you know that the send-files
directory exists for sure? You might want to check and make sure that send-files
is in the current working directory that PHP is using:
<?php
print getcwd();
?>
Create a file with the code above, visit it in the browser, and if the result is not the same directory/path that actually contains send-files
, you can do one of two things in the PHP script for uploadify:
- Change the PHP current working directory to your path for send-files:
chdir('/Users/user/Sites/directory/with/send-files/')
. You should just be able to put this in at the top of the uploadify PHP script, and it should work. But if it doesn't, post and I can help you figure out why. ;] - Create
send-files
in whatever path results from thegetcwd()
call in the PHP script above.
In either case, you need to make sure that the directory send-files
exists and that PHP has permissions to write to that directory. Either one of those options above will help with part one of that, making sure the path exists.
So then we get to part two. We need to make sure that directory is writable by the PHP script. We'll chmod
the files so that they are world writable. There are at least two ways to do this as well:
- If you know how to use the command line/Mac's Terminal app, fire it up and
cd
to the directory wheresend-files
is located:cd /Users/user/Sites/path/to/send-files
(but in this example you'd want tocd
into /to, not /send-files ;]) Then execute this:chmod -R 777 send-files
- If you don't know how to use the command line, LEARN. It's incredibly useful. But for now, if you're on a Mac, use Finder to browse to the directory in which
send-files
is located. Right click onsend-files
and click "Get Info". At the bottom of the Info pane, expand the "Sharing & Permissions" section. Click the lock in the lower right corner of the Info pane and enter your password to unlock the permission options so that you can edit them. Change the each item in the privilege column to the option "Read & Write". This will make that directory and all of its contents readable/writable.
Then try uploading your files again and see if the file ends up there. Did it work?
精彩评论