runnerjp Posted June 17, 2006 Share Posted June 17, 2006 heyyyy all againok iv created a script so that people can upload pictures so i can put them on my siteso i got this code[code]<?// Where the file is going to be placed $target_path = "uploads/";/* Add the original filename to our target path. Result is "uploads/filename.extension" */$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); // This is how we will get the temporary file...$_FILES['uploadedfile']['tmp_name'];$target_path = "uploads/";$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";} else{echo "There was an error uploading the file, please try again!";} ?>[/code]and i made a empty folder called uploads/ like so.../public_html/uploads/and placed this javascript on my page[code]<form enctype="multipart/form-data" action="uploader.php" method="POST"><P ALIGN=LEFT>Upload a screenshot of the error in JPG format maximum file size 100KB (To take a screenshot press PrintScreen button and then Paste into any image / photo program which can save as JPG):<input type="hidden" name="MAX_FILE_SIZE" value="100000" /><input type="hidden" name="FILE_TYPE_ALLOW" value="image/jpeg,image/pjpeg" /><input name="uploadedfile" type="file" /><br /><input type="submit" value="Upload File" /></form>[/code]yet i tried to upload a picture and it wnt go into my folder i created can any one help? Quote Link to comment https://forums.phpfreaks.com/topic/12251-does-any-one-know-php/ Share on other sites More sharing options...
klaroen Posted June 17, 2006 Share Posted June 17, 2006 mustn't the folder be "/uploads/"???because now you are not in another map I guess, try it out ;) Quote Link to comment https://forums.phpfreaks.com/topic/12251-does-any-one-know-php/#findComment-46752 Share on other sites More sharing options...
Fyorl Posted June 17, 2006 Share Posted June 17, 2006 you've got: [code]$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); [/code] written there twice for no apparent reason. Try echoing $target_path to try and see where it's putting it. Quote Link to comment https://forums.phpfreaks.com/topic/12251-does-any-one-know-php/#findComment-46795 Share on other sites More sharing options...
homchz Posted June 17, 2006 Share Posted June 17, 2006 the full path to the folder should be something likehome/[i]servername[/i]/public_html/uploadsif I remember correcltyreplace servername with whatever you sever is called. Quote Link to comment https://forums.phpfreaks.com/topic/12251-does-any-one-know-php/#findComment-46808 Share on other sites More sharing options...
Fyorl Posted June 17, 2006 Share Posted June 17, 2006 [!--quoteo(post=385121:date=Jun 17 2006, 05:29 PM:name=homchz)--][div class=\'quotetop\']QUOTE(homchz @ Jun 17 2006, 05:29 PM) [snapback]385121[/snapback][/div][div class=\'quotemain\'][!--quotec--]the full path to the folder should be something likehome/[i]servername[/i]/public_html/uploadsif I remember correcltyreplace servername with whatever you sever is called.[/quote]Good point, I'm not sure relative filepaths work with file uploads Quote Link to comment https://forums.phpfreaks.com/topic/12251-does-any-one-know-php/#findComment-46810 Share on other sites More sharing options...
robos99 Posted June 17, 2006 Share Posted June 17, 2006 Wouldn't $fullpath=$_SERVER['DOCUMENT_ROOT'] . '/uploads/'; be easier?What output do you get when you run this? Do you get the message that the file has been uploaded, or does it say the upload failed? Set your error reporting to E_ALL so you can catch any helpful notices.Also I'm pretty sure that <input type="hidden" name="FILE_TYPE_ALLOW" value="image/jpeg,image/pjpeg" /> is not a secure method of checking file types. You might want to put in a preg_match to check the file extensions. I guess the would go for <input type="hidden" name="MAX_FILE_SIZE" value="100000" />, you could use $_FILES['uploadedfile']['size'] to check the file size. [code]$target_path = "uploads/";$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); [/code]Why is that code repeated twice?[code]// This is how we will get the temporary file...$_FILES['uploadedfile']['tmp_name'];[/code]What purpose does that serve? Quote Link to comment https://forums.phpfreaks.com/topic/12251-does-any-one-know-php/#findComment-46819 Share on other sites More sharing options...
Fyorl Posted June 17, 2006 Share Posted June 17, 2006 [!--quoteo(post=385132:date=Jun 17 2006, 05:49 PM:name=robos99)--][div class=\'quotetop\']QUOTE(robos99 @ Jun 17 2006, 05:49 PM) [snapback]385132[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]$target_path = "uploads/";$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); [/code]Why is that code repeated twice?[code]// This is how we will get the temporary file...$_FILES['uploadedfile']['tmp_name'];[/code]What purpose does that serve?[/quote]Erm... I already mentioned that but yes, error_reporting(E_ALL) at the top of your script is always good for debugging. Quote Link to comment https://forums.phpfreaks.com/topic/12251-does-any-one-know-php/#findComment-46823 Share on other sites More sharing options...
robos99 Posted June 18, 2006 Share Posted June 18, 2006 [!--quoteo(post=385136:date=Jun 17 2006, 05:53 PM:name=Fyorl)--][div class=\'quotetop\']QUOTE(Fyorl @ Jun 17 2006, 05:53 PM) [snapback]385136[/snapback][/div][div class=\'quotemain\'][!--quotec--]Erm... I already mentioned that but yes, error_reporting(E_ALL) at the top of your script is always good for debugging.[/quote]My bad, I must have glazed over that part. Quote Link to comment https://forums.phpfreaks.com/topic/12251-does-any-one-know-php/#findComment-46889 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.