Jump to content

Uploading image to the server proved to be tricky job!


npsari

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.