image_upload?

I’m trying to upload image, but its not working
The upload_tmp_dir is /home/users/web/b2019/moo.shoresrentalscom
enter link description here

I have this php code to handle the upload

$upload_dir = "/home/users/web/b2019/moo.shoresrentalscom/public_html/properties/{$dbh->lastInsertId()}/";

$moved = move_uploaded_file($_FILES["images"]["tmp_name"], $upload_dir . $_FILES["images"]["name"]);
if(!$moved ) {
	  echo "Not uploaded ";         
	} 

But I always get the Not Uploaded thing

What file permissions are set for the folder where you’re trying to move the file to?

Also verify $upload_dir is what you want it to be.

the permissions of the 2 folders I create are 755, this is how I make them

mkdir("properties/{$dbh->lastInsertId()}",0777); 
mkdir("properties/{$dbh->lastInsertId()}/bad",0777); 

Shouldn’t the perms of both folders be 777?

and when I echo the $upload_dir, I get
/home/users/web/b2019/moo.shoresrentalscom/public_html/properties/16/

(I added public_html to the upload_tmp_dir but the folder I created is in the properties folder of the sites root, maybe I dont need the public_html part)

Are you running with full error reporting turned on? If so, there would either be an E_WARN level event generated by move_uploaded_file (indicating a permissions issue), or not (indicating an upload issue).

Sorry if I wasted yopur time, thanks for helping me…

That indicates that the script is running as directory owner since only the owner has write access. Everyone else only has read and execute access.

If the folder only contains images then execute access should not be required and you could use 644 instead of 755.

1 Like