943,169 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 314
  • PHP RSS
Aug 31st, 2010
0

Image Upload issue with extension ,jpg .png etc

Expand Post »
Hi all

I have the following script 99.9% working for uploading a single image to a database -
Storing the file in a folder and placing a link to the file in the database -

The only problem im having now is when the image is uploaded the extension of the image is removed

the file is stored as imagename. (but I need to store the image correctly)

Is there anyone here that can help me with this please.

here is the code im using

PHP Syntax (Toggle Plain Text)
  1.  
  2. $qry = "INSERT INTO mgallery(id,uid,mpicture,title,date) VALUES('','$id','$image_name','$title',now())";
  3. $result = @mysql_query($qry);
  4.  
  5. $image_ext = explode('.', $image); //split the image name with respect of " . "
  6. $image_name = date('Ymdhis'). "." . $image_ext[1]; //create unique image name with present "date & time"
  7.  
  8. $dest = "uploaded/$id";
  9.  
  10. $dest = $dest."/".$image_name;
  11.  
  12. move_uploaded_file($_FILES['profile_image']['tmp_name'], $dest); //upload image to the destination path
  13. //if($result){
  14. mysql_query("update mgallery set mpicture ='http://www.website.com/members/$dest'"); //WORKING IMAGE UPLOAD
  15. echo "Success";
  16. exit ();
  17.  
  18. }
  19. else
  20. {
  21. die("Upload failed");
  22. }
  23. }
  24. ?>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
LloydFarrell is offline Offline
101 posts
since Dec 2009
Sep 1st, 2010
0
Re: Image Upload issue with extension ,jpg .png etc
Is image the full URL or just the actual filename portion? If I was in your position, I would echo the values of $image and and $image_ext[0] and $image_ext[1] after line 5 to get more info about what is going on.
Reputation Points: 210
Solved Threads: 228
Nearly a Posting Virtuoso
chrishea is offline Offline
1,389 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: How to parse a .doc or .rtf file and extract its content in php
Next Thread in PHP Forum Timeline: For Each Loop with Array Not Quite Working Right





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC