I want to do is to resize every image to 300x300. My problem is in my current code some of the image file that was move to the upload folder are to big. I want all image file that is in the upload folder to be size 300x300.  current php code:  &lt;?php include_once('../dbc/database.php');  $db = new Connection(); $db = $db-&gt;dbConnect(); $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);  $emailCodeResult = isset($_POST['emailCodeResult']) ? $_POST['emailCodeResult'] : "";  $imageLink = isset($_POST['imageLink']) ? $_POST['imageLink'] : ""; const path = "Oppa/upload/"; $s= explode(path,$imageLink); unlink("../upload/".$s[1]);  $email = isset($_POST['email']) ? $_POST['email'] : "";  $type = $_FILES["imageInput"]["type"]; $ext = end(explode('/', $type)); $filename = uniqid() . '_' .$emailCodeResult . '.' . $ext;  move_uploaded_file($_FILES["imageInput"]["tmp_name"], "../upload/" . $filename); $location = "Oppa/upload/" . $filename;  if(!empty($_POST['email'])) {          $q = "UPDATE tbl_user SET user_image = '$location' WHERE user_email= :email ";         $query = $db-&gt;prepare($q);         $query-&gt;bindParam(':email', $email);         $results = $query-&gt;execute();         echo "1";  } ?&gt;
22542
What's the most efficient way to resize large images in PHP?  I'm currently using the  function imagecopyresampled to take high resolution images, and cleanly resize them down to a size for web viewing (roughly 700 pixels wide by 700 pixels tall).  This works great on small (under 2 MB) photos and the entire resize operation takes less than a second on the server. However, the site will eventually service photographers who may be uploading images up to 10 MB in size (or images up to 5000x4000 pixels in size).  Doing this kind of resize operation with large images tends to increase the memory usage by a very large margin (larger images can spike the memory usage for the script past 80 MB). Is there any way to make this resize operation more efficient? Should I be using an alternate image library such as ?  Right now, the resize code looks something like this  function makeThumbnail($sourcefile, $endfile, $thumbwidth, $thumbheight, $quality) {     // Takes the sourcefile (path/to/image.jpg) and makes a thumbnail from it     // and places it at endfile (path/to/thumb.jpg).      // Load image and get image size.     $img = imagecreatefromjpeg($sourcefile);     $width = imagesx( $img );     $height = imagesy( $img );      if ($width &gt; $height) {         $newwidth = $thumbwidth;         $divisor = $width / $thumbwidth;         $newheight = floor( $height / $divisor);     } else {         $newheight = $thumbheight;         $divisor = $height / $thumbheight;         $newwidth = floor( $width / $divisor );     }      // Create a new temporary image.     $tmpimg = imagecreatetruecolor( $newwidth, $newheight );      // Copy and resize old image into new image.     imagecopyresampled( $tmpimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height );      // Save thumbnail into a file.     imagejpeg( $tmpimg, $endfile, $quality);      // release the memory     imagedestroy($tmpimg);     imagedestroy($img);
66833
I have a 700Kb JPEG file (white cardboard texture) that I'm using as a background on a website.   A file this large takes too long to load for snappy page hits. I don't need the full resolution, a reduction in image quality is fine, but I do need to keep the JPEG the same size (to fill the entire screen).   What would be a good free PC or web utility that would allow me to modify a JPEG as described? I'd rather not use Photoshop or other professional software.
44624
I'm trying to reduce the size of my photo. I have tried all solutions given on this website.  My current image size is 159 KB and I have to reduce to 10 KB with 5L x 3.6w.
117191
My application is downloading a set of image files from the network, and saving them to the local iPhone disk. Some of those images are pretty big in size (widths larger than 500 pixels, for instance). Since the iPhone doesn't even have a big enough display to show the image in its original size, I'm planning on resizing the image to something a bit smaller to save on space/performance.  Also, some of those images are JPEGs and they are not saved as the usual 60% quality setting.  How can I resize a picture with the iPhone SDK, and how can I change the quality setting of a JPEG image?
89834
I have:  &lt;?php  $file=fopen(date("Y-m-d").".txt","r+") or exit("Unable to open file!");  if ($_POST["lastname"] &lt;&gt; "") {    fwrite($file,$_POST["lastname"]."\n"); }  fclose($file);  ?&gt;   but it overwrites the beginning of the file.  How do I make it insert?
70874
Do you know any good tools for nicely formatting messy php code? Preferably a script for Aptana/Eclipse, but a standalone tool will do too.
35122
I have 2,300+ pictures that I want to transfer to my phone but on their original size they take up a lot of space (6.44gb) I would like to trim is down to without sacrificing quality or resolution. I know it can be done under linux with something like pgncrush. I currently have access to a windows system and all the files are on jpeg format.  How do I do it?
4199
A   B   C   D   E   F             I don't even know. It just seemed weird.  Yes, I understand I could just avoid doing something like that. But the problem already exists with a single level.   Consider having 2 images in a post. Both exceed the maximum width of a post. One is nested in a list. Key to this issue is that my original images were much larger. They were automatically resized.  Image    List      I think it looks weird.
55945
I would like to scale an image file for each dimension differently for example 50% of the x dimension or 25% of the y dimension. Thank you very much.
65242
If I had the time, I would go through each and every photo to make sure that the dimensions and quality are pixel perfect. However, I'm in a time crunch, and need to make the couple hundred photos that are 4320 x 3240 into 950x630.   now I could- 1. Upload them into WordPress, uses native image reducing components and J query go from there. 2. Go through each and every photo, reduce file size, and proportion and bring it to Yahoo's PNG processing script.  However, maybe I'm missing a choice or alternative workflow that would allow for processing all of these photos in a clear manner without losing quality or perspectives. Any workflow suggestions?
26006
I want to show an image from an URL with a certain width and height even if it has a different size ratio.  So I want to resize (maintaining the ratio) and then cut the image to the size I want.  I can resize with html img property and I can cut with background-image.  How can I do both?  Example:  This image:     Has the size 800x600 pixels and I want to show like an image of 200x100 pixels   With img I can resize the image 200x150px:  &lt;img      style="width: 200px; height: 150px;"      src="http://i.stack.imgur.com/wPh0S.jpg"&gt;    That gives me this:    &lt;img style="width: 200px; height: 150px;" src="https://i.stack.imgur.com/wPh0S.jpg"&gt;       And with background-image I can cut the image 200x100 pixels.  &lt;div      style="background-image:            url('https://i.stack.imgur.com/wPh0S.jpg');      width:200px;      height:100px;      background-position:center;"&gt;&amp;nbsp;&lt;/div&gt;    Gives me:        &lt;div style="background-image:url('https://i.stack.imgur.com/wPh0S.jpg'); width:200px; height:100px; background-position:center;"&gt;&amp;nbsp;&lt;/div&gt;      How can I do both?  Resize the image and then cut it the size I want?
64738
I have a php script on a server to send files to recipents: they get a unique link and then they can download large files. Sometimes there is a problem with the transfer and the file is corrupted or never finishes. I am wondering if there is a better way to send large files  Code:  $f = fopen(DOWNLOAD_DIR.$database[$_REQUEST['fid']]['filePath'], 'r'); while(!feof($f)){     print fgets($f, 1024); } fclose($f);   I have seen functions such as  http_send_file http_send_data   But I am not sure if they will work.  What is the best way to solve this problem?  Regards erwing
72233
I have an image of size 1GB (.tif), with the width and height 94000x71680. I would like to chunk this image into 20000X20000 tiles so that I can process them.   How can I do this?
87644
I have created the "Gallery" content type, and added two fields: "photo," and "document." I then used the following code for uploading a file in the "document" field:  $file = file_save_upload('document', array(     'file_validate_extensions' =&gt; array('txt doc'), // Validate extensions. ));  // If the file passed validation: if ($file) { // Move the file, into the Drupal file system if ($file = file_move($file, 'public://')) {   $file-&gt;status = FILE_STATUS_PERMANENT;  // $file-&gt;file_display = 1;   $file = file_save($file);  } else {   $output = t('Failed to write the uploaded file the site\'s file folder.'); }         } else { $output = t('No file was uploaded.');  }   I am attaching this file to the node using the following code:  $customNode-&gt;field_document[$customNode-&gt;language][0] = (array)$file;   When I call node_submit() function, I get the following error:     Integrity constraint violation: 1048 Column 'field_document_display' cannot be null    Does anybody know what I am doing wrong?
52835
fopen is failing when I try to read in a very moderately sized file in PHP.  A 6 meg file makes it choke, though smaller files around 100k are just fine.  i've read that it is sometimes necessary to recompile PHP with the -D_FILE_OFFSET_BITS=64 flag in order to read files over 20 gigs or something ridiculous, but shouldn't I have no problems with a 6 meg file?  Eventually we'll want to read in files that are around 100 megs, and it would be nice be able to open them and then read through them line by line with fgets as I'm able to do with smaller files.  What are your tricks/solutions for reading and doing operations on very large files in PHP?  Update:  Here's an example of a simple codeblock that fails on my 6 meg file - PHP doesn't seem to throw an error, it just returns false.  Maybe I'm doing something extremely dumb?  $rawfile = "mediumfile.csv";  if($file = fopen($rawfile, "r")){     fclose($file); } else {   echo "fail!"; }   Another update:  Thanks all for your help, it did turn out to be something incredibly dumb - a permissions issue.  My small file inexplicably had read permissions when the larger file didn't.  Doh!
116031
I'm trying to write some PHP to upload a file to a folder on my webserver. Here's what I have:  &lt;?php     if ( !empty($_FILES['file']['tmp_name']) ) {         move_uploaded_file($_FILES['file']['tmp_name'], './' . $_FILES['file']['name']);         header('Location: http://www.mywebsite.com/dump/');         exit;     } ?&gt;  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt; &lt;html&gt;     &lt;head&gt;         &lt;title&gt;Dump Upload&lt;/title&gt;     &lt;/head&gt;     &lt;body&gt;         &lt;h1&gt;Upload a File&lt;/h1&gt;         &lt;form action="upload.php" enctype="multipart/form-data" method="post"&gt;             &lt;input type="hidden" name="MAX_FILE_SIZE" value="1000000000" /&gt;             Select the File:&lt;br /&gt;&lt;input type="file" name="file" /&gt;&lt;br /&gt;             &lt;input type="submit" value="Upload" /&gt;         &lt;/form&gt;     &lt;/body&gt; &lt;/html&gt;   I'm getting these errors:     Warning: move_uploaded_file(./test.txt) [function.move-uploaded-file]: failed to open stream: Permission denied in E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\upload.php on line 3      Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\Temp\phpA30E.tmp' to './test.txt' in E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\upload.php on line 3      Warning: Cannot modify header information - headers already sent by (output started at E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\upload.php:3) in E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\upload.php on line 4   PHP version 4.4.7 Running IIS on a Windows box. This particular file/folder has 777 permissions.  Any ideas?
121410
Hi im quite new to PHP, i have created a form for very large csv files to be uploaded to my server. Some one mentioned to me that the browser can time out due to the uploading file being to big, is this true? and if so, can it be prevented?  Thanks for your help!