Jump to content

Problem Uploading File


jponte

Recommended Posts

Hi,

I'm having issues uploading a file file to my server with a very small and simple script. It works when I do not create a new folder and leave everything in the Uploads folder but I would like to create an individual folder with the ticket number provided in the form and store all submited files there.

 

            <?php
		$ticket_number = $_POST['ticketnumber'];

		mkdir("uploads/$ticket_number", 0777);
		chmod("uploads/", 0777);
		chmod("uploads/$ticket_number", 0777);

		$mydir = "uploads/$ticket_number";

		if(chmod(realpath($myDir), 0777)) { echo 'Successfully changed dir to 0777 permissions!'; } 

        
		$target_path = "uploads";
		     

            
            if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path .'/'. $ticket_number)) {
                echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
                " has been uploaded<br>";
			echo $ticket_number; 
            } else{
                echo "There was an error uploading the file, please try again!";
            }


		clearstatcache(); 
		echo 'Permissions: ' . substr(sprintf('%o', fileperms($mydir)), -4); 
		// Result here is 0777
		?>

 

The paths are all fine. Here are the errors I get:

 

Warning: move_uploaded_file(uploads/ww) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\Documents and Settings\jack.ponte\Desktop\Website\logs\uploader.php on line 56

 

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'c:/wamp/tmp\php13E.tmp' to 'uploads/ww' in C:\Documents and Settings\jack.ponte\Desktop\Website\logs\uploader.php on line 56

 

 

Any help will be appreciated.

 

Jack P

Link to comment
https://forums.phpfreaks.com/topic/198057-problem-uploading-file/
Share on other sites

Hi,

Thanks PFMaBiSmAd. As you said, I did not have the file name to be write, So I added/changed  the following 3

 

$target_path = "uploads/$ticket_number/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
		      
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

 

Peace,

 

JP

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.