Jump to content

Recommended Posts

heyyyy all again

ok iv created a script so that people can upload pictures so i can put them on my site
so 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?
Link to comment
https://forums.phpfreaks.com/topic/12251-does-any-one-know-php/
Share on other sites

[!--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 like

home/[i]servername[/i]/public_html/uploads
if I remember correclty

replace servername with whatever you sever is called.
[/quote]

Good point, I'm not sure relative filepaths work with file uploads
Link to comment
https://forums.phpfreaks.com/topic/12251-does-any-one-know-php/#findComment-46810
Share on other sites

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?
Link to comment
https://forums.phpfreaks.com/topic/12251-does-any-one-know-php/#findComment-46819
Share on other sites

[!--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.
Link to comment
https://forums.phpfreaks.com/topic/12251-does-any-one-know-php/#findComment-46823
Share on other sites

[!--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.
Link to comment
https://forums.phpfreaks.com/topic/12251-does-any-one-know-php/#findComment-46889
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.