Jump to content

Archived

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

runnerjp

DOES ANY ONE KNOW PHP??

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?

Share this post


Link to post
Share on other sites
mustn't the folder be "/uploads/"???

because now you are not in another map I guess, try it out ;)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.