Here's the scoop: I need to be able to create folders using a PHP script and also to upload image files to those folders. Here is my code:
Creating a directory:
mkdir('[path]/images/foldername');
Uploading Images:
if ($_FILES["file"]["error"] > 0 || $_FILES["file"]["type"] != "image/jpeg") // file must be valid and .jpg
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"] . '<br />';
if(file_exists($path ."/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"], $path ."/" . $_FILES["file"]["name"]);
echo "Stored in: " . $path ."/" . $_FILES["file"]["name"];
}
}
FTP editor gives these errors:
[L] DELE 20.jpg
[L] 550 Could not delete imagename.jpg: Permission denied
then
[L] RMD foldername
[L] 550 Can't remove directory: Directory not empty
I tried changing the permissions in my FTP editor, but got this error:
[L] SITE CHMOD 777 [path]/foldername
[L] 550 Could not change perms on [path]/foldername: Operation not permitted
I tried using SSH with Putty to delete the file, but that did not work either.
Please help me!
From the File Manager in cPanel, highlight the folder you want to delete. Click the Delete link from the tool bar at the top of the page. A pop-up will appear asking you to confirm that you want to delete the folder. If you want to permanently delete the file, click the Skip trash and permanently delete the file box.
The del command displays the following prompt: Are you sure (Y/N)? To delete all of the files in the current directory, press Y and then press ENTER. To cancel the deletion, press N and then press ENTER.
After you move the uploaded file, try doing:
@chmod($path ."/" . $_FILES["file"]["name"], 0777);
or something. You might want to change the permissions to something better.
It looks like your PHP installation runs as a different user than your FTP session. Hence your php upload script can create files that your ftp user can't touch ;-).
There are essentially three ways to deal with the problem:
You could change the user account the FTP server is running under to use the same user as your PHP script (possibly www-data or httpd)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With