Jump to content


Photo

change uploaded files name


  • Please log in to reply
6 replies to this topic

#1 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 27 August 2006 - 07:12 PM

I am trying to make my form change 'uploadFile' to the name 'test', then upload the file 'test' to users/images/pictures. at the moment I get this error:
The requested URL /<br /><b>Warning</b>: rename(uploadFile,test): No such file or directory in <b>/Library/WebServer/Documents/edit.php</b> on line <b>205</b><br />Rename failed was not found on this server.
for this code:
<form enctype='multipart/form-data' action="<?php
$file_old = "uploadFile";
$file_new = "test";

if(!rename($file_old, $file_new))
{
    echo ("Rename failed");
}

move_uploaded_file ($_FILES['test'] ['tmp_name'],
       "users/images/pictures/{$_FILES['uploadFile'] ['name']}")

?>" method='post'>
Picture: <input name='uploadFile' type='file'>
<input type='submit' value='Upload'>
I am still fairly new to php, so if I am doing this completely the wrong way just tell me.

#2 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 28 August 2006 - 12:40 AM

anyone?, or can someone point me in the direction of a script that will do this... or a tutorial?

#3 Stuie_b

Stuie_b
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts
  • LocationNewcastle, UK

Posted 28 August 2006 - 12:41 AM

at the moment I get this error:
Code:

The requested URL /<br /><b>Warning</b>: rename(uploadFile,test): No such file or directory in <b>/Library/WebServer/Doc


This is because rename() function is a file function, it's used too rename one filename too another.

<form enctype='multipart/form-data' action="<?php
$file_old = "uploadFile";
$file_new = "test";

if(!rename($file_old, $file_new))
{
    echo ("Rename failed");
}
?>" method='post'>
Picture: <input name='uploadFile' type='file'>
<input type='submit' value='Upload'>
can you please explain why are you trying too change uploadfile too test? too me it doesn't make any sence?

below is an example of how i would do it you may find that it's not what your after but it may be of benifit too someone else,

form.html
<form enctype='multipart/form-data' action="upload.php" method="post">
Picture: <input name='uploadFile' type='file'>
<input type='submit' value='Upload'> 
</form>

upload.php
if($FILES['uploadFile']['name']){ //A picture was supplied lets move it too the correct dir
if(move_uploaded_file ($_FILES['test'] ['tmp_name'],"users/images/pictures/{$_FILES['uploadFile'] ['name']}"){ //Ok were moving it, but did it get there?
echo "Your picture was successfully uploaded"; //Success the picture was uploaded successfully
}else{
echo "Unable too upload your picture"; //Strangly the picture didn't upload, php should have given you a reason above
}
}else{
echo 'No Picture supplied!'; //They didnt supply a picture
}

The example above will check too see if an upload was supplied, if it finds it is it will then move the file too the pictures directory.

hope it helps

Stuie
It's all in the manual :D

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 28 August 2006 - 12:44 AM

<?php
  $fileHand = fopen('tempFile.txt', 'r');
  fclose($fileHand);
  rename( 'tempFile.txt', 'tempFile2.txt' );
?>
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 28 August 2006 - 01:10 AM

I actually dont want it to be 'test' that was just for testing purposes. I really want it to be $username. that way, I can associate the upload with the user that uploaded it.

#6 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 30 August 2006 - 02:25 AM

anyone?

#7 Satria Ox41464b

Satria Ox41464b
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 30 August 2006 - 02:34 AM

check how upload working first
http://php.net/manua...file-upload.php




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users