forumnz Posted April 6, 2007 Share Posted April 6, 2007 I am having trouble with the concept of a script that a user can browse a gif/jpg image on their comp. then write a new image name, then click upload. The image then is uploaded under the new name to the mo_images directory. Help is much appreciated please? Thanks, Sam. Quote Link to comment https://forums.phpfreaks.com/topic/45853-trouble-with-renaming-and-uploadingnot-using-db/ Share on other sites More sharing options...
hukadeeze Posted April 6, 2007 Share Posted April 6, 2007 Do you want the user to be able to browse the file system directly from the browser, or click a button that says '...browse' and get a pop-up window to browse the file system? You want the user to rename the image after they upload it to the server? Why don't they just rename it before they upload it? Quote Link to comment https://forums.phpfreaks.com/topic/45853-trouble-with-renaming-and-uploadingnot-using-db/#findComment-222789 Share on other sites More sharing options...
forumnz Posted April 6, 2007 Author Share Posted April 6, 2007 Basically. User chooses file. User enters new name. User clicks submit. File is uploaded with new name. Help? Quote Link to comment https://forums.phpfreaks.com/topic/45853-trouble-with-renaming-and-uploadingnot-using-db/#findComment-222795 Share on other sites More sharing options...
redarrow Posted April 6, 2007 Share Posted April 6, 2007 post your code ok Quote Link to comment https://forums.phpfreaks.com/topic/45853-trouble-with-renaming-and-uploadingnot-using-db/#findComment-222796 Share on other sites More sharing options...
forumnz Posted April 6, 2007 Author Share Posted April 6, 2007 As in my first post. Im having trouble with the concept. I haven't written it yet. Sam. Quote Link to comment https://forums.phpfreaks.com/topic/45853-trouble-with-renaming-and-uploadingnot-using-db/#findComment-222798 Share on other sites More sharing options...
redarrow Posted April 6, 2007 Share Posted April 6, 2007 uploads a file and renames the flle to a random number ok. good luck upload.php <?php //random number $num="123456"; $num=rand(000000,111111); // directory path. $uploaddir = 'upload_new/'; // get the dir to send file to and the file name. $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); $file=$uploadfile; $ext = substr($file, -4); $uploadfile=$uploaddir.$num.$ext; @rename($file,$uplaodfile); // if all the conditions are correct send the file to the directory. if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)){ // success echoed echo " <font color='red'>File is valid, and was successfully uploaded.</font>"; }else { //unsuccesfull echoed echo "<font color='red'>File was unsuccesful sorry</font>"; } // show the form. echo" <form enctype='multipart/form-data' action='upload.php' method='POST'> <input type='hidden' name='MAX_FILE_SIZE' value='30000000000000000000000'> send this file <input name='userfile' type='file' > <input type='submit' name='submit' value='Send File'> </form>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/45853-trouble-with-renaming-and-uploadingnot-using-db/#findComment-222801 Share on other sites More sharing options...
hukadeeze Posted April 6, 2007 Share Posted April 6, 2007 He wants the user to choose a filename. Quote Link to comment https://forums.phpfreaks.com/topic/45853-trouble-with-renaming-and-uploadingnot-using-db/#findComment-222806 Share on other sites More sharing options...
redarrow Posted April 6, 2007 Share Posted April 6, 2007 not tested ok. <?php // directory path. $uploaddir = 'upload_new/'; // get the dir to send file to and the file name. $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); $file_name=$uploadfile; @rename($file_name,$uplaodfile); // if all the conditions are correct send the file to the directory. if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)){ // success echoed echo " <font color='red'>File is valid, and was successfully uploaded.</font>"; }else { //unsuccesfull echoed echo "<font color='red'>File was unsuccesful sorry</font>"; } // show the form. echo" <form enctype='multipart/form-data' action='upload.php' method='POST'> <input type='hidden' name='MAX_FILE_SIZE' value='30000000000000000000000'> please provide a file name: <br> send this file <input name='file_name' type='text' > <br> send this file <input name='userfile' type='file' > <input type='submit' name='submit' value='Send File'> </form>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/45853-trouble-with-renaming-and-uploadingnot-using-db/#findComment-222809 Share on other sites More sharing options...
hukadeeze Posted April 6, 2007 Share Posted April 6, 2007 point out all the problems and do none of the work... I like my style Quote Link to comment https://forums.phpfreaks.com/topic/45853-trouble-with-renaming-and-uploadingnot-using-db/#findComment-223069 Share on other sites More sharing options...
forumnz Posted April 6, 2007 Author Share Posted April 6, 2007 Huh? Can someone please help me? Quote Link to comment https://forums.phpfreaks.com/topic/45853-trouble-with-renaming-and-uploadingnot-using-db/#findComment-223100 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.