Re: [PHP] image upload keeps file name ?
On Thu, 2010-04-01 at 10:51 +0100, Matthew Croud wrote: Hi Guys, Can someone confirm for me that the code below will move an uploaded file and give it the same name as the original image file name ? $file_dir = /home/uploads; foreach($_FILES as $file_name = $file_array) { echo path: .$file_array[tmp_name].br/\n; echo name: .$file_array[name].br/\n; echo type: .$file_array[type].br/\n; echo size: .$file_array[size].br/\n; $UploadName[$num] = $file_array[name]; $num++; if (is_uploaded_file($file_array[tmp_name])) { move_uploaded_file($file_array[tmp_name], $file_dir/. $file_array[name]) or die (Couldn't copy); echo file was moved!br/; } } Many thanks, Yes, the original filename comes from the [name] array element. However, if someone is uploading a filename with the same name as one that already exists, you will be overwriting it. For peace of mind, I've always found it best to save the file using the tmp_name given to it by PHP, and store this against the original filename in a database. You can then use PHP to deliver the file back to the user when it's needed as either a download or something displayed in the browser. This works nicely with storing files outside of the web root, which will prevent people from maliciously uploading files to attempt to break your server and/or app. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] image upload keeps file name ?
I use the follwing function for moving files: public function moveFile($file,$targetdir=../uploads/images/) { $fileName = $file['name']; $ext = substr($fileName, strrpos($fileName, '.') + 1); do { $targetfilename=md5(date(m.d.y.h.i.s).basename($fileName)).'.'.$ext; $fullname=$targetdir.$targetfilename; }while(file_exists($fullname)); move_uploaded_file($file[tmp_name],$fullname); return $fullname; } Call the fn as : foreach($_FILES as $file_name = $filearray) { if( $filearray['error']=='') { $filenametobestored=moveFile($filearray); /*Enter name into db here*/ } } this will make sure you never over write anyfiles.. Midhun Girish On Thu, Apr 1, 2010 at 3:25 PM, Ashley Sheridan a...@ashleysheridan.co.ukwrote: of the web root, which will prevent people from maliciously uploadi
Re: [PHP] Image upload
Robert Fitzpatrick wrote: I have a small application that ran on one server and now gives me a problem with uploading images on a new server. I am running PHP 4.4.4 now on this server and hoping it is just something that needs adjusted in php.ini, but cannot seem to find. The file is posted as a file fields in a multipart/form-data form, the application tests the file with getimagesize() shown below. I am getting the die response in the browser. I tried echo of the file and it prints a random file name under the /tmp directory on this CentOS Linux system. If I sleep for 10 seconds, the file gets created and gone after the script finishes. Can someone suggest what my problem may be? no. but start by stopping the assumption that getimagesize() returns something equivelant to false to mean the same thing as that the file does not exist (or is not an image file.) this might help: http://php.net/is_uploaded_file also check it's not a permissions issue (i.e. the file is being created but the webserver cannot subsequently read the file) if (!getimagesize($_FILES['filPhoto']['tmp_name'])) { die('The file you are attempting to upload is not an image file.'); } else { snip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Image upload
Jochem Maas wrote: Robert Fitzpatrick wrote: I have a small application that ran on one server and now gives me a problem with uploading images on a new server. I am running PHP 4.4.4 now on this server and hoping it is just something that needs adjusted in php.ini, but cannot seem to find. The file is posted as a file fields in amultipart/form-data form, the application tests the file with getimagesize() shown below. I am getting the die response in the browser. I tried echo of the file and it prints a random file name under the /tmp directory on this CentOS Linux system. If I sleep for 10 seconds, the file gets created and gone after the script finishes. Can someone suggest what my problem may be? no. but start by stopping the assumption that getimagesize() returns something equivelant to false to mean the same thing as that the file does not exist (or is not an image file.) this might help: http://php.net/is_uploaded_file Yes, actually that is done first, the getimagesize is used it the script to test it as an image. This was written by someone else and worked prior to moving servers. This is a more complete snippet of the code: if (is_uploaded_file($_FILES['filPhoto']['tmp_name'])) { // use getimagesize to make sure it's an image file if (!getimagesize($_FILES['filPhoto']['tmp_name'])) { die('The file you are attempting to upload is not an image file.'); snip also check it's not a permissions issue (i.e. the file is being created but the webserver cannot subsequently read the file) The /tmp directory where it is created is set with 777 perms. I have not checked the destination, but the script does not appear to get back the above point, giving us the die response. -- Robert -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Image upload
On Mon, February 5, 2007 4:29 pm, Robert Fitzpatrick wrote: I have a small application that ran on one server and now gives me a problem with uploading images on a new server. I am running PHP 4.4.4 now on this server and hoping it is just something that needs adjusted in php.ini, but cannot seem to find. The file is posted as a file fields in a multipart/form-data form, the application tests the file with getimagesize() shown below. I am getting the die response in the browser. I tried echo of the file and it prints a random file name under the /tmp directory on this CentOS Linux system. If I sleep for 10 seconds, the file gets created and gone after the script finishes. Can someone suggest what my problem may be? The file always goes away when the script finishes. See: http://php.net/move_uploaded_file if (!getimagesize($_FILES['filPhoto']['tmp_name'])) { die('The file you are attempting to upload is not an image file.'); Try various things like file_exists on the file to see if you are getting the file at all. fopen/fread the first N bytes and compare them to what you are uploading, to see if the data that gets there is the data you sent. getimagesize() only reads the first N bytes and then interprets that to decide what kind of file it is, and how big the width/height are, etc. I dunno exactly what N is, but it's relatively small. Different file formats have different size N, and PHP has to figure out what to do for all of them, so maybe it just reads the largest N, or maybe it reads a few bytes and then decides how many to read for the rest of the meta-info. At any rate, if you can fread a couple hundred bytes, and it matches what you uploaded, then you know that something is wrong with the original image and getimagesize() -- You could FTP it up just like your logo or buttons, and use getimagesize() on it, and it STILL wouldn't work. Actually, that's another good test to run: FTP the file up to your images directory and see what getimagesize does on that. } else { snip -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Image upload
PS I forgot that the $_FILES array also has an 'error' field in it. Check that! On Mon, February 5, 2007 4:29 pm, Robert Fitzpatrick wrote: I have a small application that ran on one server and now gives me a problem with uploading images on a new server. I am running PHP 4.4.4 now on this server and hoping it is just something that needs adjusted in php.ini, but cannot seem to find. The file is posted as a file fields in a multipart/form-data form, the application tests the file with getimagesize() shown below. I am getting the die response in the browser. I tried echo of the file and it prints a random file name under the /tmp directory on this CentOS Linux system. If I sleep for 10 seconds, the file gets created and gone after the script finishes. Can someone suggest what my problem may be? if (!getimagesize($_FILES['filPhoto']['tmp_name'])) { die('The file you are attempting to upload is not an image file.'); } else { snip -- Robert -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] image upload problem
[snip] The Code is running properly.But I dont Know Where The uploaded image is Stored in the server.I checked /tmp directory,but image is not there,is there any function where i can specify the location of the server where my image is to be stored i also tired move_uploaded_image() function .but its not working .I am waiting reply from any one [/snip] http://www.php.net/move_uploaded_file -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] image upload problem
suresh kumar wrote: Hi, hi ([EMAIL PROTECTED]([EMAIL PROTECTED]([EMAIL PROTECTED](*%([EMAIL PROTECTED]([EMAIL PROTECTED]@# I am waiting reply from any one do we have someone here called 'any one'? how about you reply to one of the people who answer your questions. PS - the tmp file is removed at the end of the request. PPS - ?php echo it is temporarily stored at {$_FILES['ufile']['tmp_name']}; ? - Yahoo! India Answers: Share what you know. Learn something new Click here Catch all the FIFA World Cup 2006 action on Yahoo! India Click here -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Image upload form
Okay, I started seeing some of my mistakes. I am still having a great deal of trouble: newfile returns: 0fdae2e9e6aa43f067a9dd780a5a36a6.jpg image_file returns: images/jpg/test/0fdae2e9e6aa43f067a9dd780a5a36a6.jpg images/jpg/test is set to 777 but I still get (Could not move file to destination). What am I missing? Thanks! ?php error_reporting(E_ALL); $uploaddir = images/jpg/test/; print_r($_FILES); $local_file = $_FILES['userfile']['tmp_name']; if (sizeof($local_file)) { //try to get image size; this returns false if this is not an actual image file. $image_test = getimagesize($local_file); if ($image_test !== false) { $mime_type = $_FILES['userfile']['type']; switch($mime_type) { case image/jpeg: $pext = 'jpg'; break; case image/tiff: $pext = 'tif'; break; default: echo The file you are trying to upload is an image, but it is not a tif or jpeg and therefore unacceptable.; } } else { echo The file you are trying to upload is not a valid image file; } $newfile = md5(date(l-F-j-Y i:s)).'.'.$pext; $image_file = $uploaddir . $newfile; // print_r($newfile); // print_r($image_file); if(!move_uploaded_file($newfile,$image_file)) { echo 'Could not move file to destination'; exit; } else { echo 'image file ?php echo $newfile ? uploaded.'; } } ? form enctype=multipart/form-data action=?php echo $_SERVER['PHP_SELF']; ? method=POST input type=hidden name=MAX_FILE_SIZE value=30 / !-- Name of input element determines name in $_FILES array -- Cartoon: input name=userfile type=file / input type=submit value=Upload File / /form -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Image upload form
Richard Davey wrote: Hello Jack, Wednesday, June 15, 2005, 5:38:11 PM, you wrote: JJ newfile returns: 0fdae2e9e6aa43f067a9dd780a5a36a6.jpg JJ image_file returns: JJ images/jpg/test/0fdae2e9e6aa43f067a9dd780a5a36a6.jpg JJ images/jpg/test is set to 777 but I still get (Could not move file to JJ destination). What am I missing? Thanks! This directory needs to be absolute - i.e. the COMPLETE path: /usr/home/jack/images/jpg/test Thanks, Richard, Still no soap: I changed $uploaddir = /home/jack/public_html/amyportnoy/images/jpg/test; and $image_file = $uploaddir . '/' . $newfile; Now $image_file returns the valid path of: /home/jack/public_html/amyportnoy/images/jpg/test/09992d5379dd0a0cf376aab82241a66d.jpg but it still does not copy the file to that location. However the error has changed: if (is_uploaded_file($newfile)) { if(!move_uploaded_file($newfile,$image_file)) { echo 'Could not move file to destination'; exit; } else { echo 'image file ?php echo $newfile ? uploaded.'; } } else { echo 'Problem with ' . $newfile; } } And I'm getting an error message of Problem with 6a26590fb45fd86e58954ba91d5580a4.jpg So i guess it's not uploading for some reason? Here's the whole thing I have so far once again, with several mods: ?php error_reporting(E_ALL); $uploaddir = /home/jack/public_html/amyportnoy/images/jpg/test; print_r($_FILES); if ($_FILES['userfile']['error'] 0) { echo 'Problem: '; switch ($_FILES['userfile']['error']) { case 1: echo 'File exceeds maximum upload size limit (upload_max_filesize).'; break; case 2: echo 'File exceeds maximum size limit (max_file_size).'; break; case 3: echo 'File was only partially uploaded.'; break; case 4: echo 'No file was uploaded.'; break; }//end switch }//end if error 0 $local_file = $_FILES['userfile']['tmp_name']; if (sizeof($local_file)) { //try to get image size; this returns false if this is not an actual image file. $image_test = getimagesize($local_file); if ($image_test !== false) { $mime_type = $_FILES['userfile']['type']; switch($mime_type) { case image/jpeg: $pext = 'jpg'; break; case image/tiff: $pext = 'tif'; break; default: echo The file you are trying to upload is an image, but it is not a tif or jpeg and therefore unacceptable.; } } else { echo The file you are trying to upload is not a valid image file; } $newfile = md5(date(l-F-j-Y i:s)).'.'.$pext; $image_file = $uploaddir . '/' . $newfile; // print_r($newfile); print_r($image_file); if (is_uploaded_file($newfile)) { if(!move_uploaded_file($newfile,$image_file)) { echo 'Could not move file to destination'; exit; } else { echo 'image file ' . $newfile . 'uploaded.'; } } else { echo 'Problem with ' . $newfile; } } ? form enctype=multipart/form-data action=?php echo $_SERVER['PHP_SELF']; ? method=POST input type=hidden name=MAX_FILE_SIZE value=30 / !-- Name of input element determines name in $_FILES array -- Cartoon: input name=userfile type=file / input type=submit value=Upload File / /form -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Image upload form
On Thursday 16 June 2005 00:38, Jack Jackson wrote: //try to get image size; this returns false if this is not an actual image file. $image_test = getimagesize($local_file); if ($image_test !== false) { $mime_type = $_FILES['userfile']['type']; $_FILES['userfile']['type'] contains the mime-type that is provided by the browser and will vary depending on browser and hence extremely unreliable. In fact the returned value from getimagesize() already has mime-type info, use that instead. $newfile = md5(date(l-F-j-Y i:s)).'.'.$pext; $image_file = $uploaddir . $newfile; // print_r($newfile); // print_r($image_file); if(!move_uploaded_file($newfile,$image_file)) { echo 'Could not move file to destination'; exit; } The file pointed to by $newfile doesn't exist. You need to move ... $local_file = $_FILES['userfile']['tmp_name']; ... $localfile -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- New Year Resolution: Ignore top posted posts -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Image upload form
Yes, Jason, Those did it! Thanks so much for the help! Jason Wong wrote: On Thursday 16 June 2005 00:38, Jack Jackson wrote: //try to get image size; this returns false if this is not an actual image file. $image_test = getimagesize($local_file); if ($image_test !== false) { $mime_type = $_FILES['userfile']['type']; $_FILES['userfile']['type'] contains the mime-type that is provided by the browser and will vary depending on browser and hence extremely unreliable. In fact the returned value from getimagesize() already has mime-type info, use that instead. $newfile = md5(date(l-F-j-Y i:s)).'.'.$pext; $image_file = $uploaddir . $newfile; // print_r($newfile); // print_r($image_file); if(!move_uploaded_file($newfile,$image_file)) { echo 'Could not move file to destination'; exit; } The file pointed to by $newfile doesn't exist. You need to move ... $local_file = $_FILES['userfile']['tmp_name']; ... $localfile -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Image upload not working correctly
Thanks for the reponse. Yes, the destination paths look fine and the PHP error log displays no errors. Any other ideas? Thanks. Jason Wong [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Thursday 14 October 2004 02:40, Dave Grant wrote: echo Thumb image uploaded to .$thumbPath.br /\n; echo Full image uploaded to .$fullPath.br /\n; Do these look OK? Everything works fine, except that the images are simply not there when we go look for them. The best explanation I can come up with is that they are not moved, but I have no idea why. I've done this with no problem on my personal site. Is it a problem with the move_uploaded_file function? Any ideas? What does the PHP error log say? -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Faith goes out through the window when beauty comes in at the door. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Image upload not working correctly
Just to clarify, everything looks like it works fine except for moving the images to the destination path. The images upload, the server recognizes them, but they don't get moved to the destination path. Thanks. Jason Wong [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Thursday 14 October 2004 02:40, Dave Grant wrote: echo Thumb image uploaded to .$thumbPath.br /\n; echo Full image uploaded to .$fullPath.br /\n; Do these look OK? Everything works fine, except that the images are simply not there when we go look for them. The best explanation I can come up with is that they are not moved, but I have no idea why. I've done this with no problem on my personal site. Is it a problem with the move_uploaded_file function? Any ideas? What does the PHP error log say? -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Faith goes out through the window when beauty comes in at the door. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Image upload not working correctly
Please do not top-post. On Thursday 14 October 2004 23:52, Dave Grant wrote: Thanks for the reponse. Yes, the destination paths look fine and the PHP error log displays no errors. Any other ideas? move_uploaded_file() _will_ spit out an error if there are any problems. So if you're _positive_ FULL error reporting is enabled logged and the error log shows nothing then I would be inclined to assume that the move_uploaded_file() operation was executed successfully. In that case, are you positive you're looking in the correct place for the destination file? If you're still having problems, post some self-contained, concise[1] code to illustrate your problem. [1] concise meaning the bare minimum, eg in your case code to handle either thumb image or full image but not both, etc. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* The Heineken Uncertainty Principle: You can never be sure how many beers you had last night. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Image upload not working correctly
On Thursday 14 October 2004 02:40, Dave Grant wrote: echo Thumb image uploaded to .$thumbPath.br /\n; echo Full image uploaded to .$fullPath.br /\n; Do these look OK? Everything works fine, except that the images are simply not there when we go look for them. The best explanation I can come up with is that they are not moved, but I have no idea why. I've done this with no problem on my personal site. Is it a problem with the move_uploaded_file function? Any ideas? What does the PHP error log say? -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Faith goes out through the window when beauty comes in at the door. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] image upload woes
Edward Peloke wrote --- napísal:: I have code which attempts to upload some files and create thumbnails. The same code on one server works ok, the same code on another server throws an error everytime I hit submit that says The document contains no data...it appears to be a javascript error. It is not an error that I am throwing. Has anyone ever had this problem? Thanks, Eddie I bet that the script is dying for some reason. Turn display_errors on or check the logs, the real reason should be there somewhere. And it's not javascript. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] image upload woes
[snip] I have code which attempts to upload some files and create thumbnails. The same code on one server works ok, the same code on another server throws an error everytime I hit submit that says The document contains no data...it appears to be a javascript error. It is not an error that I am throwing. Has anyone ever had this problem? [/snip] I am sure that someone has had a problem like this, but if you believe it to be a JavaScript problem why would you not ask a JavaScript list? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] image upload woes
* Thus wrote Edward Peloke: I have code which attempts to upload some files and create thumbnails. The same code on one server works ok, the same code on another server throws an error everytime I hit submit that says The document contains no data...it appears to be a javascript error. It is not an error that I am throwing. Has anyone ever had this problem? diff -u otherserver:/usr/local/lib/php.ini /usr/local/lib/php.ini WARNING: The information contained in this message and any attachments is intended only for the use of the individual or entity to which it is for some reason I'm always tempted to make some sort of comment here. Curt -- First, let me assure you that this is not one of those shady pyramid schemes you've been hearing about. No, sir. Our model is the trapezoid! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] image upload
Sorry, there was typo in the code I sent previously. Here is the right code but the same problem - secont image is with incorrect header: ?php $nw=100; //The Width Of The Thumbnails //$rw=400; $ipath = ./pics; //Path To Place Where Images Are Uploaded. $tpath = ./thumbs;//Path To Place Where Thumbnails Are Uploaded function LoadJpeg ($imgname) { $im = @imagecreatefromjpeg ($imgname); /* Attempt to open */ if (!$im) { /* See if it failed */ $im = imagecreate (150, 30); /* Create a blank image */ $bgc = imagecolorallocate ($im, 255, 255, 255); $tc = imagecolorallocate ($im, 0, 0, 0); imagefilledrectangle ($im, 0, 0, 150, 30, $bgc); /* Output an errmsg */ imagestring ($im, 1, 5, 5, Error loading $imgname, $tc); } return $im; } $dimensions = getimagesize($file); $thname = $tpath/$file_name; //$rname = $ipath/$file_name; $w=$dimensions[0]; $h=$dimensions[1]; $c=$nw/$w; //$c2=$rw/w; $nh=$h*$c; //The Height Of The Thumbnails //$rh=$h*$c2; //The Height Of The Large Pictures $img = LoadJpeg($file); //$img2 = LoadJpeg($file); $thumb = imagecreatetruecolor($nw,$nh); //$large = imagecreatetruecolor($rw,$rh); imagecopyresampled($thumb,$img,0,0,0,0,$nw,$nh,$w,$h); // imagecopyresampled($large,$img2,0,0,0,0,$rw,$rh,$w,$h); imagejpeg($thumb,$thname,95); // imagejpeg($large,$rname,95); imagedestroy($img2); ? On 6 Oct 2003 at 8:09, Jason Wong wrote: On Monday 06 October 2003 00:32, Yury B. wrote: Hi I need to upload two resized images out from one jpg image. I use following code to do it: [snip] This code is working perfectly but produces only one uploaded and resized image (I comented out the lines that I add for second image) If I take out comments from the code on the second image - this script doesn't work - it produces two files on the server but only one of them is working the other one shows error of wrong hedding. How should I upload two resized files? I know it's possible but how can I fit everything in one portion of code? Check the values of all your variables -- in particular $rw, as it doesn't seem to be initialised. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* One thing about the past. It's likely to last. -- Ogden Nash */ God is our provider http://www.body-builders.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] image upload
Thank you for all help I have just figured out that there is other variable prob. See pointer ---: ?php $nw=100; //The Width Of The Thumbnails //$rw=400; $ipath = ./pics; //Path To Place Where Images Are Uploaded. $tpath = ./thumbs;//Path To Place Where Thumbnails Are Uploaded function LoadJpeg ($imgname) { $im = @imagecreatefromjpeg ($imgname); /* Attempt to open */ if (!$im) { /* See if it failed */ $im = imagecreate (150, 30); /* Create a blank image */ $bgc = imagecolorallocate ($im, 255, 255, 255); $tc = imagecolorallocate ($im, 0, 0, 0); imagefilledrectangle ($im, 0, 0, 150, 30, $bgc); /* Output an errmsg */ imagestring ($im, 1, 5, 5, Error loading $imgname, $tc); } return $im; } $dimensions = getimagesize($file); $thname = $tpath/$file_name; //$rname = $ipath/$file_name; $w=$dimensions[0]; $h=$dimensions[1]; $c=$nw/$w; -- //$c2=$rw/w; $nh=$h*$c; //The Height Of The Thumbnails //$rh=$h*$c2; //The Height Of The Large Pictures $img = LoadJpeg($file); //$img2 = LoadJpeg($file); $thumb = imagecreatetruecolor($nw,$nh); //$large = imagecreatetruecolor($rw,$rh); imagecopyresampled($thumb,$img,0,0,0,0,$nw,$nh,$w,$h); // imagecopyresampled($large,$img2,0,0,0,0,$rw,$rh,$w,$h); imagejpeg($thumb,$thname,95); // imagejpeg($large,$rname,95); imagedestroy($img2); ? On 6 Oct 2003 at 8:09, Jason Wong wrote: On Monday 06 October 2003 00:32, Yury B. wrote: Hi I need to upload two resized images out from one jpg image. I use following code to do it: [snip] This code is working perfectly but produces only one uploaded and resized image (I comented out the lines that I add for second image) If I take out comments from the code on the second image - this script doesn't work - it produces two files on the server but only one of them is working the other one shows error of wrong hedding. How should I upload two resized files? I know it's possible but how can I fit everything in one portion of code? Check the values of all your variables -- in particular $rw, as it doesn't seem to be initialised. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* One thing about the past. It's likely to last. -- Ogden Nash */ God is our provider http://www.body-builders.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] image upload
On Monday 06 October 2003 00:32, Yury B. wrote: Hi I need to upload two resized images out from one jpg image. I use following code to do it: [snip] This code is working perfectly but produces only one uploaded and resized image (I comented out the lines that I add for second image) If I take out comments from the code on the second image - this script doesn't work - it produces two files on the server but only one of them is working the other one shows error of wrong hedding. How should I upload two resized files? I know it's possible but how can I fit everything in one portion of code? Check the values of all your variables -- in particular $rw, as it doesn't seem to be initialised. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* One thing about the past. It's likely to last. -- Ogden Nash */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] image upload question
Nothing really. I did happen across a couple of tutorials from phpbuilder.com http://www.phpbuilder.com/columns/michael20020712.php3?print_mode=1 and http://www.phpbuilder.com/columns/bealers2904.php3?page=3print_mode=1 may be able to piece something together from these two articles. let me know if you find out anything. thanks, TD Hey Tyler, Did you get any progress on this? I'm trying to do the same thing. Johnny _ Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Image upload into database
Are you trying to upload the same image as you did at home? If so, size isn't the problem if you can do it from home. It might be a timeout issue. There might be something in php.ini you can set for timeout. You can specify the max filesize to upload in php.ini also. Good luck, Tyler On Wed, 24 Jul 2002 19:43:37 -0400 (EDT) Jesse Lawrence [EMAIL PROTECTED] wrote: I've setup an image upload feature on a site, which uploads images into a mysql database. The uploads are working absolutely as expected on my local computer (the server), but when someone else tried to upload, only 1/3 of the image was uploaded. Could it be a matter of size? I was originally using just a Blob, and have since switched to a Long Blob. Any thoughts or comments on this would be greatly appreciated. Thanks a bunch, Jesse __ Post your ad for free now! http://personals.yahoo.ca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Image upload into database
Just curious why you don't upload the image to a dir and just store the link in the db? -Original Message- From: Jesse Lawrence [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 24, 2002 7:44 PM To: [EMAIL PROTECTED] Subject: [PHP] Image upload into database I've setup an image upload feature on a site, which uploads images into a mysql database. The uploads are working absolutely as expected on my local computer (the server), but when someone else tried to upload, only 1/3 of the image was uploaded. Could it be a matter of size? I was originally using just a Blob, and have since switched to a Long Blob. Any thoughts or comments on this would be greatly appreciated. Thanks a bunch, Jesse __ Post your ad for free now! http://personals.yahoo.ca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Image upload into database
You need to look at the differences between your server and the live one. The only real way to test is to have both you AND another tester (preferably on a slow computer with 56k connection) to try uploading the SAME IMAGE FILE to both servers. This will rule out problems with the data type (eg blob). Then test with larger images/files. Likely problems will be: - the file size is too big, and the PHP script is timing out before it can finish (check php.ini for differences in script timeouts) - there is a maximum file size for uploaded files on the server, which is different to - the file isn't too big, but the script is still timing out (check php.ini for differences in script timeouts) - the 56k connection (different to your office set-up) means that files upload way too slow, or get interrupted If possible you should compare your php.ini to the one of the live server, and try to match them up, which will help. Justin French on 25/07/02 9:43 AM, Jesse Lawrence ([EMAIL PROTECTED]) wrote: I've setup an image upload feature on a site, which uploads images into a mysql database. The uploads are working absolutely as expected on my local computer (the server), but when someone else tried to upload, only 1/3 of the image was uploaded. Could it be a matter of size? I was originally using just a Blob, and have since switched to a Long Blob. Any thoughts or comments on this would be greatly appreciated. Thanks a bunch, Jesse __ Post your ad for free now! http://personals.yahoo.ca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Image upload and scaling
Someone just mentioned ImageMagick... Check it out: http://www.imagemagick.org/ ImageMagickTM is a robust collection of tools and libraries to read, write, and manipulate an image in many image formats (over 68 major formats) including popular formats like TIFF, JPEG, PNG, PDF, PhotoCD, and GIF. With ImageMagick you can create images dynamically, making it suitable for Web applications. You can also resize, rotate, sharpen, color reduce, or add special effects to an image and save your completed work in the same or differing image format. Image processing operations are available from the command line, as well as through C, C++, Perl, or Java programming interfaces. Or you can check out the built in gd functions. http://www.php.net/manual/en/ref.image.php Sam On 3/11/02 12:21 PM, P.Agenbag [EMAIL PROTECTED] wrote: Hi, I am trying to make a util whereby ppl can upload their own images to my server for me to automatically display them. The below code works fine, but I have the following problem. It only works fne if everyone complies to a standard of a set width and height for the image. This is not always possible, so I'm looking for a way to accept the image in any form they have and then to scale it to fit within an acceptable height/width range. This I need help with, so if someone could hep me ( at the hand of my current code) I would be very pleased. Thanks Petre below my code snippet -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Image Upload
This is a very good exercise you shouldn't skip by using prefabricated tools. Just use a input type=file for the first part and the PHP documentation for the second - the procedure in itself is really simple, but you'll have the opportunity to understand some nice technicalities in the process. Bogdan [EMAIL PROTECTED] wrote: Does anyone have a good script for uploading an image and storing it in a mySQL database. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] image upload - determining image resolution in pixels ?
open the file with gd and use imagesx() and imagesy() ?php $img = imagecreatefromjpeg($file_name) $x = imagesx($img); $y = imagesy($img); ? gd does not handel quicktime, only jpeg, gif (older, dont go there), png, tiff I think thts it. I havent checked. but never the less, images, not movies. -- Chris Lee [EMAIL PROTECTED] Nicolas Mermet [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Hi, I was wondering if there is a way to analize an uploaded jpeg file in order to extract its resolution in pixels. Would that be also possible with a quicktime movie ? thanks, Nicolas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] image upload - determining image resolution in pixels ?
On Tue, May 22, 2001 at 10:38:32AM -0700, Nicolas Mermet wrote : I was wondering if there is a way to analize an uploaded jpeg file in order to extract its resolution in pixels. GetImageSize() is a favourite one here. Would that be also possible with a quicktime movie ? Possibly, but no one has done a constribution yet to php. - Markus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Image Upload??
Done that, doesn't work! Brave Cobra - Original Message - From: Toby Dacre [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, May 16, 2001 3:29 AM Subject: Re: [PHP] Image Upload?? chmod the file or directory so that php can access it it doesn't run as you! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Image Upload??
Maybe I ought to mention that I don't have direct access to this server. It's a F2S account, I'm trying to upload to. BC - Original Message - From: Brave Cobra [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, May 16, 2001 10:01 AM Subject: Re: [PHP] Image Upload?? Done that, doesn't work! Brave Cobra - Original Message - From: Toby Dacre [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, May 16, 2001 3:29 AM Subject: Re: [PHP] Image Upload?? chmod the file or directory so that php can access it it doesn't run as you! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Image Upload??
And then I found the answer. The PHP module of the Apache server at F2S is running in Safe mode(like the error said), meaning that you can't do uploads in PHP. This safe mode prohibits that. The only alternative is uploading in CGI or Perl. Another challange to let PHP and CGI work together! BC - Original Message - From: Brave Cobra [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, May 16, 2001 12:52 PM Subject: Re: [PHP] Image Upload?? Maybe I ought to mention that I don't have direct access to this server. It's a F2S account, I'm trying to upload to. BC - Original Message - From: Brave Cobra [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, May 16, 2001 10:01 AM Subject: Re: [PHP] Image Upload?? Done that, doesn't work! Brave Cobra - Original Message - From: Toby Dacre [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, May 16, 2001 3:29 AM Subject: Re: [PHP] Image Upload?? chmod the file or directory so that php can access it it doesn't run as you! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Image Upload??
From phpinfo() on f2s.com upload_max_filesize 2M So, something like, @copy($file, /path/to . $file_name) or die (Blam, something's up!); should work - haven't got time to try it at the moment. James. What am I doing wrong here? Is there a way to get around the temporary folder? Tnx Brave Cobra -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Image Upload??
But as you can see too : upload_tmp_dir has no value, so I'm guessing this won't work. I'm still getting errors with PHP, no problem in CGI though. BC - Original Message - From: James Holloway [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, May 16, 2001 2:47 PM Subject: Re: [PHP] Image Upload?? From phpinfo() on f2s.com upload_max_filesize 2M So, something like, @copy($file, /path/to . $file_name) or die (Blam, something's up!); should work - haven't got time to try it at the moment. James. What am I doing wrong here? Is there a way to get around the temporary folder? Tnx Brave Cobra -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Image Upload??
chmod the file or directory so that php can access it it doesn't run as you! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Image Upload
Kyle Mathews wrote: I'm looking for some code that will upload images to my server from a form submission. I'd also like it to check for a max file size of the images. Any help would be appreciated. what about reading the manual? there are variables that contain the file size. http://www.php.net/manual/en/features.file-upload.php -- php developer / CoreTrek AS| Genius, n.: A chemist who discovers a Sandnes / Rogaland / Norway| laundry additive that rhymes with web: http://www.moijk.net/ | bright. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Image Upload
Kyle Mathews [EMAIL PROTECTED] wrote: Hello: I'm looking for some code that will upload images to my server from a form submission. I'd also like it to check for a max file size of the images. look at the getimagesize() function -- Henrik Hansen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]