RTS Posted August 27, 2006 Share Posted August 27, 2006 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:[code]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.[/code]for this code:[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'> [/code]I am still fairly new to php, so if I am doing this completely the wrong way just tell me. Quote Link to comment Share on other sites More sharing options...
RTS Posted August 28, 2006 Author Share Posted August 28, 2006 anyone?, or can someone point me in the direction of a script that will do this... or a tutorial? Quote Link to comment Share on other sites More sharing options...
Stuie_b Posted August 28, 2006 Share Posted August 28, 2006 [quote]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 [/quote]This is because rename() function is a file function, it's used too rename one filename too another.[code]<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'> [/code]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[code]<form enctype='multipart/form-data' action="upload.php" method="post">Picture: <input name='uploadFile' type='file'><input type='submit' value='Upload'> </form>[/code]upload.php[code]if($FILES['uploadFile']['name']){ //A picture was supplied lets move it too the correct dirif(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}[/code]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 helpsStuie Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 28, 2006 Share Posted August 28, 2006 <?php $fileHand = fopen('tempFile.txt', 'r'); fclose($fileHand); rename( 'tempFile.txt', 'tempFile2.txt' );?> Quote Link to comment Share on other sites More sharing options...
RTS Posted August 28, 2006 Author Share Posted August 28, 2006 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. Quote Link to comment Share on other sites More sharing options...
RTS Posted August 30, 2006 Author Share Posted August 30, 2006 anyone? Quote Link to comment Share on other sites More sharing options...
Satria Ox41464b Posted August 30, 2006 Share Posted August 30, 2006 check how upload working firsthttp://php.net/manual/en/features.file-upload.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.