npsari Posted May 21, 2007 Share Posted May 21, 2007 I use the below code to upload images $target_path = "images/"; $target_path = $target_path . basename( $_FILES['Image1']['name']); $_FILES['Image1']['tmp_name']; $target_path = "images/"; $filename = basename( $_FILES['Image1']['name']); if (file_exists($target_path . $filename)) { $filename = time() . '_' . $filename; } $target_path .= $filename; if(move_uploaded_file($_FILES['Image1']['tmp_name'], $target_path)) { echo "Image1: was uploaded successfully!"; } else{ print "Image1: could NOT be uploaded!"; } The above code renames the images too However, when a user uploads images which the name has spaces The code doesnt get rid of the space, and i get trouble displaying them later What part can i add to to the code to take space from the image name, then rename it Quote Link to comment https://forums.phpfreaks.com/topic/52383-uploading-image-to-the-server-proved-to-be-tricky-job/ Share on other sites More sharing options...
Wildbug Posted May 21, 2007 Share Posted May 21, 2007 You can use str_replace() to replace spaces with underscores or something. Quote Link to comment https://forums.phpfreaks.com/topic/52383-uploading-image-to-the-server-proved-to-be-tricky-job/#findComment-258491 Share on other sites More sharing options...
npsari Posted May 21, 2007 Author Share Posted May 21, 2007 Is this how i say it $f = array('', '_''); echo str_replace($f, $Image1); can you show me how Quote Link to comment https://forums.phpfreaks.com/topic/52383-uploading-image-to-the-server-proved-to-be-tricky-job/#findComment-258494 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 21, 2007 Share Posted May 21, 2007 Whenever you want to know how to do something in php, always read the manual at php.net - a good trick is to put in the URL address bar...php.net/funcname - where funcname is the function you want to learn more about ex) php.net/str_replace will bring up information on the str_replace function Quote Link to comment https://forums.phpfreaks.com/topic/52383-uploading-image-to-the-server-proved-to-be-tricky-job/#findComment-258496 Share on other sites More sharing options...
npsari Posted May 21, 2007 Author Share Posted May 21, 2007 Ohh, ok, cool i will go and check it out Quote Link to comment https://forums.phpfreaks.com/topic/52383-uploading-image-to-the-server-proved-to-be-tricky-job/#findComment-258497 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.