supanoob Posted February 28, 2007 Share Posted February 28, 2007 i have the following code to upload and rename a file. i want to change a couple of things 1) i want it to check make sure the file is gif/jpeg/jpg 2) i want it to put the file type back on the end. at the moment the url looks like this: http://tordonline.p.sitesquat.com/profile/01 could someone advise on how to do both those things <?php if ($_GET['step'] == 'upload_new_complete') { // Your file name you are uploading $file_name = $HTTP_POST_FILES['ufile']['name']; // random 4 digit to add to our file name // some people use date and time in stead of random digit //combine random digit to you file name to create new file name //use dot (.) to combile these two variables $new_file_name=$images_had.$account_id; //set where you want to store files //in this example we keep file in folder upload //$new_file_name = new upload file name //for example upload file name cartoon.gif . $path will be upload/cartoon.gif $path= "/home/porky/public_html/profile/".$new_file_name; if($ufile !=none) { if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)) { echo "Successful<BR/>"; //$new_file_name = new file name //$HTTP_POST_FILES['ufile']['size'] = file size //$HTTP_POST_FILES['ufile']['type'] = type of file $profile_image=($new_file_name.$HTTP_POST_FILES['type']); $sql2="UPDATE tord_accounts SET profile_image='$profile_image' WHERE account_id='$account_id'"; if(mysql_query($sql2)); echo "File Name :".$new_file_name."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>"; echo "<a href=\"/profile/$new_file_name\">Click Here to View</a><br>"; echo "Image Thumbnail:<br> <img src=\"/profile/$new_file_name\" width=\"150\" height=\"150\">"; } else { echo "Error"; } } } ?> Link to comment https://forums.phpfreaks.com/topic/40587-renaminguploading/ Share on other sites More sharing options...
supanoob Posted March 1, 2007 Author Share Posted March 1, 2007 bump Link to comment https://forums.phpfreaks.com/topic/40587-renaminguploading/#findComment-196888 Share on other sites More sharing options...
ted_chou12 Posted March 1, 2007 Share Posted March 1, 2007 getimagesize($tmp_filename); and see if this function doesnt return false, as well as explode($tmp_filename); and see if the extensions are right. Ted Link to comment https://forums.phpfreaks.com/topic/40587-renaminguploading/#findComment-196900 Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 $arrfileName = explode(".", $tmp_filename); $srtExt = $arrfileName[1]; now you can use the $strExt where you want... Link to comment https://forums.phpfreaks.com/topic/40587-renaminguploading/#findComment-196919 Share on other sites More sharing options...
ted_chou12 Posted March 1, 2007 Share Posted March 1, 2007 explode(".", $tmp_filename); sorry, i used the explode wrong... Link to comment https://forums.phpfreaks.com/topic/40587-renaminguploading/#findComment-196929 Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 never mind sometimes it happen... Link to comment https://forums.phpfreaks.com/topic/40587-renaminguploading/#findComment-196937 Share on other sites More sharing options...
ted_chou12 Posted March 1, 2007 Share Posted March 1, 2007 thanks for tolerance. Ted Link to comment https://forums.phpfreaks.com/topic/40587-renaminguploading/#findComment-196938 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.