SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing image name while being uploaded

    Guys how do you use the below function to change the image name as it is uploaded. I don't want the original name but a tailored one.

    This is the code for the default name. Is there a better function?

    Code:
    if (move_uploaded_file($_FILES['image1']['tmp_name'], "./{$_FILES['image1']['name']}")) {
    Cheers

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have found a solution, here it is if you are interested.

    Code:
    // Pick a file extension
    	if (eregi('^image/p?jpeg(;.*)?$', $_FILES['image1']['type'])) {
    		$extension = '.jpg';
    	} else {
    		$extension = '.gif';
    	}
    	
    	// The complete path/filname
    	$filename = './custom_name' . $extension;
    	
    	// Copy the file (if it is deemed safe)
    	if (is_uploaded_file($_FILES['image1']['tmp_name']) and copy($_FILES['image1']['tmp_name'], $filename)) {
    		echo "<p>File stored successfully as $filename.</p>";
    	} else {
    		echo "<p>Could not upload the file.</p>";
    	}


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •