File upload problem

Reply

Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is online now Online
Posting Whiz in Training

File upload problem

 
0
  #1
Mar 25th, 2009
have a script which i found online,through google for uploading and resizing photos when they are uploaded.
It works well,the only problem is that there are some images when i upload them they are not detected as a file,but others are uploaded well.
for example image of this properties is not detected.
(Dimension:3264*2448
camera model,DSC-W150
type:JPEG Image.
size:2,70 MB.
)
below is the script:
  1. <?php
  2. $user=$_SESSION['user'];
  3.  
  4. if(isset($_POST['submit']))
  5. {
  6. include"config.php";
  7.  
  8.  
  9.  
  10. //make sure this directory is writable!
  11. $path_thumbs ='C:/wamp/www/website/thumb/';
  12.  
  13. //the new width of the resized image, in pixels.
  14. $img_thumb_width = 120; //
  15.  
  16. $extlimit = "yes"; //Limit allowed extensions? (no for all extensions allowed)
  17. //List of allowed extensions if extlimit = yes
  18. $limitedext = array(".gif",".jpg",".png",".JPG",".JPEG",".jpeg",".bmp");
  19.  
  20. //the image -> variables
  21. $file_type = $_FILES['vImage']['type'];
  22. $file_name = $_FILES['vImage']['name'];
  23. $file_size = $_FILES['vImage']['size'];
  24. $file_tmp = $_FILES['vImage']['tmp_name'];
  25.  
  26. //check if you have selected a file.
  27. if(!is_uploaded_file($file_tmp)){
  28. echo "Error: Please select a file to upload!. <br><a href=profilephoto.php>back</a>";
  29. exit(); //exit the script and don't process the rest of it!
  30. }
  31. //check the file's extension
  32. $ext = strrchr($file_name,'.');
  33. $ext = strtolower($ext);
  34. //uh-oh! the file extension is not allowed!
  35. if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
  36. echo "Wrong file extension. <br>--<a href=profilephoto.php>back</a>";
  37. exit();
  38. }
  39. //so, whats the file's extension?
  40. $getExt = explode ('.', $file_name);
  41. $file_ext = $getExt[count($getExt)-1];
  42.  
  43. //create a random file name
  44. $rand_name = md5(time());
  45. $rand_name= rand(0,999999999);
  46. //the new width variable
  47. $ThumbWidth = $img_thumb_width;
  48.  
  49. //////////////////////////
  50. // CREATE THE THUMBNAIL //
  51. //////////////////////////
  52.  
  53. //keep image type
  54. if($file_size){
  55. if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
  56. $new_img = imagecreatefromjpeg($file_tmp);
  57. }elseif($file_type == "image/x-png" || $file_type == "image/png"){
  58. $new_img = imagecreatefrompng($file_tmp);
  59. }elseif($file_type == "image/gif"){
  60. $new_img = imagecreatefromgif($file_tmp);
  61. }
  62. //list the width and height and keep the height ratio.
  63. list($width, $height) = getimagesize($file_tmp);
  64. //calculate the image ratio
  65. $imgratio=$width/$height;
  66. if ($imgratio>1){
  67. $newwidth = $ThumbWidth;
  68. $newheight = $ThumbWidth/$imgratio;
  69. }else{
  70. $newheight = $ThumbWidth;
  71. $newwidth = $ThumbWidth*$imgratio;
  72. }
  73. //function for resize image.
  74. if (function_exists(imagecreatetruecolor)){
  75. $resized_img = imagecreatetruecolor($newwidth,$newheight);
  76. }else{
  77. die("Error: Please make sure you have GD library ver 2+");
  78. }
  79. //the resizing is going on here!
  80. imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  81. //finally, save the image
  82. ImageJpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext");
  83. ImageDestroy ($resized_img);
  84. ImageDestroy ($new_img);
  85.  
  86.  
  87. }
  88.  
  89. //ok copy the finished file to the thumbnail directory
  90. move_uploaded_file ($file_tmp, "$path_big/$rand_name.$file_ext");
  91. /*
  92. Don't want to copy it to a separate directory?
  93. Want to just display the image to the user?
  94. Follow the following steps:
  95.  
  96. 2. Uncomment this code:
  97. /*
  98. /* UNCOMMENT THIS IF YOU WANT */
  99. //echo "IMG:<img src=\"$path_big/$rand_name.$file_ext\" />";
  100. //exit();
  101. //*/
  102.  
  103. //and you should be set!
  104.  
  105. //success message, redirect to main page.
  106. //$msg = urlencode("$rand_name.$file_ext was uploaded! <a href=\"Resize.php\">Upload More?</a>");
  107. //header("Location: Resize.php?msg=$msgn
  108. include"myprofile.php";
  109.  
  110. include"config.php";
  111. $query="UPDATE login SET photo='$rand_name.$file_ext' WHERE user='$user'";
  112. $result=mysql_query($query);
  113. $check="UPDATE profile SET photos='$rand_name.$file_ext' WHERE users='$user'";
  114. $jibu=mysql_query($check);
  115. if(!$result||!$jibu){
  116. echo"failed to send to database";
  117. }
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126. exit();
  127.  
  128.  
  129. }else{
  130.  
  131. //if there is a message, display it
  132. if(isset($_GET['msg']))
  133. {
  134. //but decode it first!
  135. echo "<p>".urldecode($_GET['msg'])."</p>";
  136. }
  137. //the upload form
  138.  
  139.  
  140. }
  141.  
  142.  
  143. ?>
this line here is the one return errors.
  1. //check if you have selected a file.
  2. if(!is_uploaded_file($file_tmp)){
  3. echo "Error: Please select a file to upload!. <br><a href=profilephoto.php>back</a>";
  4. exit(); //exit the script and don't process the rest of it!
  5. }

i need your suggestions,what i should change here?
bcoz this is the biggest problem i`m experiencing.
Last edited by mrcniceguy; Mar 25th, 2009 at 9:24 am. Reason: .
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,744
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: File upload problem

 
0
  #2
Mar 26th, 2009
Try changing the upload_max_filesize in php.ini . The default filesize for upload is 2mb.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is online now Online
Posting Whiz in Training

Re: File upload problem

 
0
  #3
Mar 27th, 2009
i changed the value to
upload_max_filesize = 5M
but the problem is still there...
i`m totally comfused..
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,744
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: File upload problem

 
0
  #4
Mar 27th, 2009
Hmm.. Try printing out $_FILES .. Check if $_FILES['vImage']['error'] is set ! I tested your script with image size varying from 1 mb to 4 mb. Works fine
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is online now Online
Posting Whiz in Training

Re: File upload problem

 
0
  #5
Mar 27th, 2009
i did as you said,and i got error displaying a number which equals to one(1).
down is how did.. check if i`m right..

  1. //the image -> variables
  2. $file_type = $_FILES['vImage']['type'];
  3. $file_name = $_FILES['vImage']['name'];
  4. $file_size = $_FILES['vImage']['size'];
  5. $file_tmp = $_FILES['vImage']['tmp_name'];
  6. $error=$_FILES['vImage']['error'];
  7.  
  8. //check if you have selected a file.
  9. if(!is_uploaded_file($file_tmp)){
  10. echo "Error: Please select a file to upload!. <br><a href=profilephoto.php>back</a><br>";
  11. echo"$error";
  12. exit(); //exit the script and don't process the rest of it!
  13. }
Last edited by mrcniceguy; Mar 27th, 2009 at 10:31 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,744
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: File upload problem

 
0
  #6
Mar 28th, 2009
Well, that error number corresponds to the max_file_size in php.ini . http://in2.php.net/manual/en/feature...oad.errors.php ! Are you sure you changed the correct php.ini file (and restarted apache ?) I can't think of anything else other than the max file size.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is online now Online
Posting Whiz in Training

Re: File upload problem

 
0
  #7
Mar 28th, 2009
thankx nav33n for ur contribution,me too i can`t thinkanymore of this issue.....
coz now i change the value
from

post_max_size = 8M
upload_max_filesize = 2M
max_execution_time = 30
max_input_time = 60
memory_limit = 8M

Change to:
post_max_size = 750M
upload_max_filesize = 750M
max_execution_time = 5000
max_input_time = 5000
memory_limit = 1000M

but nothing changed...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,744
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: File upload problem

 
0
  #8
Mar 28th, 2009
Lets see if someone else can solve this for you
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 478
Reputation: maydhyam is an unknown quantity at this point 
Solved Threads: 1
maydhyam's Avatar
maydhyam maydhyam is offline Offline
Posting Pro in Training

Re: File upload problem

 
0
  #9
Apr 1st, 2009
I remember I had a similar problem, and did all the changes suggested here, but the script actually only worked after I restarted the machine (my machine was relocated...so it was a complete restart)...

hope this helps!!!
The man who in view of gain thinks of righteousness; who in the view of danger is prepared to give up his life; and who does not forget an old agreement however far back it extends - such a man may be reckoned a complete man.
~ Confucius, The Confucian Analects
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is online now Online
Posting Whiz in Training

Re: File upload problem

 
0
  #10
Apr 1st, 2009
ok!i will take a look,thankx.
Also if you check my Code in these line
  1. $imgratio=$width/$height;
  2. if ($imgratio>1){
  3. $newwidth = $ThumbWidth;
  4. $newheight = $ThumbWidth/$imgratio;
  5. }else{
  6. $newheight = $ThumbWidth;
  7. $newwidth = $ThumbWidth*$imgratio;
  8. }
pictures are not in a good Ratio,some appears distorted.
if there is something i can change to make the appearance of the photos nice please Tell me.
i`ll appreciate.
Last edited by mrcniceguy; Apr 1st, 2009 at 9:31 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC