brown2005 Posted February 27, 2007 Share Posted February 27, 2007 Hi I want to upload an image to http://www.mywebsite.com/include/images/ but i want it to be renamed to {$name1}_{$name2} i think that is how you write it so if $name1 = "cars" $name2 = "person" it would be cars_person thanks richard Link to comment https://forums.phpfreaks.com/topic/40336-image-upload/ Share on other sites More sharing options...
monk.e.boy Posted February 27, 2007 Share Posted February 27, 2007 $new_name = $name1.'_'.$name2; monk.e.boy Link to comment https://forums.phpfreaks.com/topic/40336-image-upload/#findComment-195161 Share on other sites More sharing options...
brown2005 Posted February 27, 2007 Author Share Posted February 27, 2007 if($_SERVER['REQUEST_METHOD'] == "POST") { $uploaddir = "http://www.links-bid.com/include/adverts/"; $pext = getFileExtension($imgfile_name); $pext = strtolower($pext); if (($pext != "jpg") && ($pext != "jpeg") && ($pext != "gif")) { print "<h1>ERROR</h1>Image Extension Unknown.<br>"; print "<p>Please upload only a JPEG image with the extension .jpg or .jpeg ONLY<br><br>"; print "The file you uploaded had the following extension: $pext</p>\n"; unlink($imgfile); exit(); } $imgsize = GetImageSize($imgfile); if (($imgsize[0] > 250) || ($imgsize[1] > 200)) { $tmpimg = tempnam("/tmp", "MKUP"); system("djpeg $imgfile >$tmpimg"); system("pnmscale -xy 250 200 $tmpimg | cjpeg -smoo 10 -qual 50 >$imgfile"); unlink($tmpimg); } $final_filename = str_replace(" ", "_", $imgfile_name); $newfile = $uploaddir . "/$final_filename"; if (is_uploaded_file($imgfile)) { if (!copy($imgfile,"$newfile")) { print "Error Uploading File."; exit(); } } unlink($imgfile); print("<img src=\"$final_filename\">"); } where would I put that in this script though? please Link to comment https://forums.phpfreaks.com/topic/40336-image-upload/#findComment-195171 Share on other sites More sharing options...
brown2005 Posted February 27, 2007 Author Share Posted February 27, 2007 $final_filename = str_replace(" ", "_", $imgfile_name); i see that is the filename being uploaded so do i simply do: $final_filename = $name1.'_'.$name2; or do i need to include str_replace(" ", "_", $imgfile_name); that? Link to comment https://forums.phpfreaks.com/topic/40336-image-upload/#findComment-195189 Share on other sites More sharing options...
brown2005 Posted February 27, 2007 Author Share Posted February 27, 2007 i tried $final_filename = $name1.'_'.$name2; but it doesnt work as it doesnt put the extension on the end of the file, so how would i add the extension please? Link to comment https://forums.phpfreaks.com/topic/40336-image-upload/#findComment-195196 Share on other sites More sharing options...
monk.e.boy Posted February 27, 2007 Share Posted February 27, 2007 $new_name = $name1.'_'.$name2.'.'.$pext; Note the .'.'. looks confusing. A dot appends text to a string. So we are appending the string '.' with the extension 'jpg' to get '.jpg' and this is appended to the file name: '/usr/bin/kittens/hello_world.jpg' monk.e.boy Link to comment https://forums.phpfreaks.com/topic/40336-image-upload/#findComment-195213 Share on other sites More sharing options...
brown2005 Posted February 27, 2007 Author Share Posted February 27, 2007 $uploaddir = "adverts"; $pext = getFileExtension($imgfile_name); $pext = strtolower($pext); if(($pext != "jpg") && ($pext != "jpeg") && ($pext != "gif")) { print "<h1>ERROR</h1>Image Extension Unknown.<br>"; print "<p>Please upload only a JPEG image with the extension .jpg or .jpeg ONLY<br><br>"; print "The file you uploaded had the following extension: $pext</p>\n"; unlink($imgfile); exit(); } $final_filename = $amount.'_'.$place.'.'.$pext; $newfile = $uploaddir . "/$final_filename"; if(is_uploaded_file($imgfile)) { if (!copy($imgfile,"$newfile")) { print "Error Uploading File."; exit(); } } unlink($imgfile); } i have that but it is not putting the image in the folder, any ideas? Link to comment https://forums.phpfreaks.com/topic/40336-image-upload/#findComment-195221 Share on other sites More sharing options...
monk.e.boy Posted February 27, 2007 Share Posted February 27, 2007 do you get error messages? If not, it may be folder permissions. You need to allow apache read/write to the upload folder. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/40336-image-upload/#findComment-195330 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.