Jump to content


Photo

File upload script Modification


  • Please log in to reply
4 replies to this topic

#1 markspec87

markspec87
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 07 September 2006 - 04:51 PM

I have a script to upload files, its pretty simple.

form

<form enctype="multipart/form-data" action="uploader.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>


uploader.php

$target = "../uploads/";
$target = $target . basename( $_FILES['uploaded']['name']);

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
?>


My question is how could i modify the uploader to add something onto the filename?

i.e add the variable $id onto the front of every uploaded file?

#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 07 September 2006 - 05:07 PM

$id = "prefix_here";
$target = "../uploads/"; 
$target = $target . $id . basename( $_FILES['uploaded']['name']);


Ray

#3 markspec87

markspec87
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 07 September 2006 - 05:47 PM

Ive run into another problem aswell.

When i upload to /uploads/ its absolutely fine.

However if i do /uploads/files/ It throws the error:

Warning: move_uploaded_file(./uploads/files/PF.txt): failed to open stream: Permission denied in /home/terraarm/public_html/includes/uploader.php on line 13


any ideas?



#4 markspec87

markspec87
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 07 September 2006 - 11:44 PM

BUMP, any ideas? :)

#5 TEENFRONT

TEENFRONT
  • Members
  • PipPipPip
  • Advanced Member
  • 338 posts

Posted 08 September 2006 - 12:24 AM

you need to give the /uploads/files folder full read n write access, so CHMOD to 666
Teenfront.co.uk : Free Teen Chat -  FunkySmileys.co.uk : MSN Smileys -  ArcadeMonkey.co.uk : Free Flash Games
8Baller.co.uk : Free Multiplayer Pool [url=http://8Baller.co.uk]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users