| | |
File upload problem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2008
Posts: 217
Reputation:
Solved Threads: 4
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:
this line here is the one return errors.
i need your suggestions,what i should change here?
bcoz this is the biggest problem i`m experiencing.
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:
php Syntax (Toggle Plain Text)
<?php $user=$_SESSION['user']; if(isset($_POST['submit'])) { include"config.php"; //make sure this directory is writable! $path_thumbs ='C:/wamp/www/website/thumb/'; //the new width of the resized image, in pixels. $img_thumb_width = 120; // $extlimit = "yes"; //Limit allowed extensions? (no for all extensions allowed) //List of allowed extensions if extlimit = yes $limitedext = array(".gif",".jpg",".png",".JPG",".JPEG",".jpeg",".bmp"); //the image -> variables $file_type = $_FILES['vImage']['type']; $file_name = $_FILES['vImage']['name']; $file_size = $_FILES['vImage']['size']; $file_tmp = $_FILES['vImage']['tmp_name']; //check if you have selected a file. if(!is_uploaded_file($file_tmp)){ echo "Error: Please select a file to upload!. <br><a href=profilephoto.php>back</a>"; exit(); //exit the script and don't process the rest of it! } //check the file's extension $ext = strrchr($file_name,'.'); $ext = strtolower($ext); //uh-oh! the file extension is not allowed! if (($extlimit == "yes") && (!in_array($ext,$limitedext))) { echo "Wrong file extension. <br>--<a href=profilephoto.php>back</a>"; exit(); } //so, whats the file's extension? $getExt = explode ('.', $file_name); $file_ext = $getExt[count($getExt)-1]; //create a random file name $rand_name = md5(time()); $rand_name= rand(0,999999999); //the new width variable $ThumbWidth = $img_thumb_width; ////////////////////////// // CREATE THE THUMBNAIL // ////////////////////////// //keep image type if($file_size){ if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){ $new_img = imagecreatefromjpeg($file_tmp); }elseif($file_type == "image/x-png" || $file_type == "image/png"){ $new_img = imagecreatefrompng($file_tmp); }elseif($file_type == "image/gif"){ $new_img = imagecreatefromgif($file_tmp); } //list the width and height and keep the height ratio. list($width, $height) = getimagesize($file_tmp); //calculate the image ratio $imgratio=$width/$height; if ($imgratio>1){ $newwidth = $ThumbWidth; $newheight = $ThumbWidth/$imgratio; }else{ $newheight = $ThumbWidth; $newwidth = $ThumbWidth*$imgratio; } //function for resize image. if (function_exists(imagecreatetruecolor)){ $resized_img = imagecreatetruecolor($newwidth,$newheight); }else{ die("Error: Please make sure you have GD library ver 2+"); } //the resizing is going on here! imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); //finally, save the image ImageJpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext"); ImageDestroy ($resized_img); ImageDestroy ($new_img); } //ok copy the finished file to the thumbnail directory move_uploaded_file ($file_tmp, "$path_big/$rand_name.$file_ext"); /* Don't want to copy it to a separate directory? Want to just display the image to the user? Follow the following steps: 2. Uncomment this code: /* /* UNCOMMENT THIS IF YOU WANT */ //echo "IMG:<img src=\"$path_big/$rand_name.$file_ext\" />"; //exit(); //*/ //and you should be set! //success message, redirect to main page. //$msg = urlencode("$rand_name.$file_ext was uploaded! <a href=\"Resize.php\">Upload More?</a>"); //header("Location: Resize.php?msg=$msgn include"myprofile.php"; include"config.php"; $query="UPDATE login SET photo='$rand_name.$file_ext' WHERE user='$user'"; $result=mysql_query($query); $check="UPDATE profile SET photos='$rand_name.$file_ext' WHERE users='$user'"; $jibu=mysql_query($check); if(!$result||!$jibu){ echo"failed to send to database"; } exit(); }else{ //if there is a message, display it if(isset($_GET['msg'])) { //but decode it first! echo "<p>".urldecode($_GET['msg'])."</p>"; } //the upload form } ?>
php Syntax (Toggle Plain Text)
//check if you have selected a file. if(!is_uploaded_file($file_tmp)){ echo "Error: Please select a file to upload!. <br><a href=profilephoto.php>back</a>"; exit(); //exit the script and don't process the rest of it! }
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: .
•
•
Join Date: Mar 2008
Posts: 217
Reputation:
Solved Threads: 4
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..
down is how did.. check if i`m right..
php Syntax (Toggle Plain Text)
//the image -> variables $file_type = $_FILES['vImage']['type']; $file_name = $_FILES['vImage']['name']; $file_size = $_FILES['vImage']['size']; $file_tmp = $_FILES['vImage']['tmp_name']; $error=$_FILES['vImage']['error']; //check if you have selected a file. if(!is_uploaded_file($file_tmp)){ echo "Error: Please select a file to upload!. <br><a href=profilephoto.php>back</a><br>"; echo"$error"; exit(); //exit the script and don't process the rest of it! }
Last edited by mrcniceguy; Mar 27th, 2009 at 10:31 pm.
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.
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*
*PM asking for help will be ignored*
•
•
Join Date: Mar 2008
Posts: 217
Reputation:
Solved Threads: 4
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...
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...
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!!!
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
~ Confucius, The Confucian Analects
•
•
Join Date: Mar 2008
Posts: 217
Reputation:
Solved Threads: 4
ok!i will take a look,thankx.
Also if you check my Code in these line
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.
Also if you check my Code in these line
php Syntax (Toggle Plain Text)
$imgratio=$width/$height; if ($imgratio>1){ $newwidth = $ThumbWidth; $newheight = $ThumbWidth/$imgratio; }else{ $newheight = $ThumbWidth; $newwidth = $ThumbWidth*$imgratio; }
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.
![]() |
Similar Threads
- File upload problem (PHP)
- File upload help (PHP)
- excel file upload problem (ASP.NET)
- File Upload To Server - Problem (ASP)
- File upload - advanced help (PHP)
- file upload code.....need attention (PHP)
- File upload problem (PHP)
Other Threads in the PHP Forum
- Previous Thread: i can't load my image in preview
- Next Thread: php url regex
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube






