简体   繁体   中英

How to upload file to folder inside another folder

I am using this code to upload files, but when I upload a file to one folder it works , but when I want to upload a file to folder inside a folder, it doesn't work ,, as in the following code ..

   $imageFile = $_FILES['origialImg']['tmp_name'];
            $filename = basename( $_FILES['origialImg']['name']);
            if(strstr($_FILES["origialImg"]["type"],"image")){
        list($width, $height) = getimagesize($imageFile);

        $src = imagecreatefromjpeg($imageFile);
        $orig_h = ($height/$width)* $orig_w;

        $tmp = imagecreatetruecolor($orig_w, $orig_h);
        imagecopyresampled($tmp, $src, 0,0,0,0,$orig_w,$orig_h,$width,$height);
        imagejpeg($tmp, $folder1."/".$folder2."/".$filename,100);
        imagedestroy($tmp);
        imagedestroy($src);

edit

yes, this is the error reporting

Warning: imagejpeg(): Unable to open 'images/big/216389_10150266713175744_609155743_9327201_766531_n.jpg' for writing: Permission denied in /var/www/GazaPlaces/account/photos.php 

So it works when you upload a file to a folder but it doesn't work when you upload a file to a folder in that folder?

Check the folder exists and that you have permission to upload into it, you can CHMOD the folder using your FTP client.

To see if the folder is there use: file_exists() . You can CHMOD the folder using php with chmod() .

You could split the file path and do a ftp_chdir() for each directory in the file path before uploading the file.

Did you check if you have write permission on the second folder?

You will have to chmod the folder images/big/ to make it writable for the server. you can do it within php if the folder belongs to the server and just needs write permissions. see php's chmod

you need to give proper permissions (writable) to the target folder from main folder.

like folder1/folder2 both have the writable permissions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM