Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2009
    Posts
    226
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Strange issue with file upload

    Having an odd problem with a script that adds details of a document / file to a mySQL table and also uploads (or should upload) the physical file.

    The portion which should upload the file is:
    Code:
    if ($addnewresource) {  
    		$target_dir = "resources/";
    		$target_file = $target_dir . basename($_FILES["_ResourceFileName"]["name"]);
    		echo $target_file;
    		if (move_uploaded_file($_FILES["_ResourceFileName"]["tmp_name"], $target_file)) {
            	echo "The file ". basename( $_FILES["ResourceFileName"]["name"]). " has been uploaded.";
    			print_r($_FILES);
        } else {
            echo "Sorry, there was an error uploading your file.";
    		print_r($_FILES);
        }
    }
    I added a print_r in order to try and troubleshoot, but the output isn't very explanatory:
    Code:
    Array ( [_ResourceFileName] => Array ( [name] => test.jpg [type] => image/jpeg [tmp_name] => /tmp/phpFxaTaQ [error] => 0 [size] => 83288 ) )
    Any idea what's going on? The query to add the document's data (title, date added, description etc.) to the table works fine, it's just the document doesn't upload.
    The specified "resources" folder is in place and has the same permissions as other folders on the site
    The form for adding the document is of enctype "multipart/form-data" as required.
    There is sufficient space on the web hosting to upload loads of files

    ???
    Last edited by galahad3; 09-14-2017 at 05:00 PM.

  2. #2
    New to the CF scene
    Join Date
    Sep 2017
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Is there an error_log being created? Does it contain anything?

    How big is the file being uploaded?

  3. #3
    New to the CF scene
    Join Date
    Sep 2017
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Also is file_upload enabled in teh php.ini file if its a webhost? sometimes they disable this for security.

  4. #4
    Regular Coder Vege's Avatar
    Join Date
    Jan 2008
    Posts
    794
    Thanks
    20
    Thanked 110 Times in 109 Posts
    File upload works (print_r displays /tmp/phpFxaTaQ that is your uploaded file)

    move_uploaded_file fails.
    This could be because webserver process don't have permission to write to said folder. Test it first with full ugo+rwx (777) permissions. Also make sure webserver process has execute permissions to full folder path leading to said folder.
    After that it could be extra security measures like apparmor or selinux.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •