Jump to content


Photo

DOES ANY ONE KNOW PHP??


  • Please log in to reply
7 replies to this topic

#1 runnerjp

runnerjp
  • Members
  • PipPipPip
  • Advanced Member
  • 2,214 posts

Posted 17 June 2006 - 06:01 PM

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

<?
// 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!";
} 
?>

and i made a empty folder called uploads/ like so.../public_html/uploads/

and placed this javascript on my page
<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>

yet i tried to upload a picture and it wnt go into my folder i created can any one help?

#2 klaroen

klaroen
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 17 June 2006 - 07:38 PM

mustn't the folder be "/uploads/"???

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

#3 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 17 June 2006 - 09:53 PM

you've got:
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
written there twice for no apparent reason. Try echoing $target_path to try and see where it's putting it.
[table]



Don't worry, the printer fairies will sort it out.

#4 homchz

homchz
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts
  • LocationLee, New Hampshire

Posted 17 June 2006 - 10:29 PM

the full path to the folder should be something like

home/servername/public_html/uploads


if I remember correclty

replace servername with whatever you sever is called.

#5 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 17 June 2006 - 10:35 PM

[!--quoteo(post=385121:date=Jun 17 2006, 05:29 PM:name=homchz)--][div class=\'quotetop\']QUOTE(homchz @ Jun 17 2006, 05:29 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
the full path to the folder should be something like

home/servername/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
[table]



Don't worry, the printer fairies will sort it out.

#6 robos99

robos99
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 17 June 2006 - 10:49 PM

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.

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
Why is that code repeated twice?

// This is how we will get the temporary file...
$_FILES['uploadedfile']['tmp_name'];
What purpose does that serve?

#7 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 17 June 2006 - 10:53 PM

[!--quoteo(post=385132:date=Jun 17 2006, 05:49 PM:name=robos99)--][div class=\'quotetop\']QUOTE(robos99 @ Jun 17 2006, 05:49 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
Why is that code repeated twice?

// This is how we will get the temporary file...
$_FILES['uploadedfile']['tmp_name'];
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.
[table]



Don't worry, the printer fairies will sort it out.

#8 robos99

robos99
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 18 June 2006 - 02:28 AM

[!--quoteo(post=385136:date=Jun 17 2006, 05:53 PM:name=Fyorl)--][div class=\'quotetop\']QUOTE(Fyorl @ Jun 17 2006, 05:53 PM) View Post[/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.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users