PHP - Mystery: Shrinking Php Filesize
Good morning Experts!
My code creates a PNG file output 505 x 600 pixels, 24bit, 96dpi. The average file size is 130kb. No mystery there. Here is the mystery: when I open the file using ACDSee (v10) and then "save as" (even with the same filename), the file size SHRINKS to about 80kb. All the specs remain the same and I can see no difference in the image! How in the world... What could an ACDSee file-save-as be doing and how do I do it in PHP? Doing a file-save-as in Windows Paint has the same result! So I have tried to reduce the filesize in the code using compression and filters: from imagepng($Image, $ImageName) to imagepng($Image, $ImageName, 9, PNG_ALL_FILTERS). No difference. I tried running through PNGCRUSH, file size only goes to 112kb. The mystery is driving me crazy. Any ideas of what to check in my code or image? Any ideas of tricks to try in the code? A 30% filesize reduction is too great to ignore. I've attached a not-yet-shrunk file for your entertainment (It appears that the upload program wont allow my original as it is 120kb) Thank you in advance for all your ideas! Similar TutorialsHaving an issue where a peice of code is just being ignored. <?php if($_POST){ $image =$_FILES["image"]["name"]; $img = $_FILES['image']['tmp_name']; $size= filesize($_FILES["image"]["name"]); $maxsize= 400; if ($size > $maxsize*1024){ echo "File too big"; exit(); } else { That is the first bit of code in the page, if i upload a image within the size allowance everything is ok, but if i try one which is a lot bigger, it ignore the if $size > statement and just continues on and throws a bunch of errors. Any ideas? I'm trying to get the filesize() of a file based on a retrieval of filename from the database. The file is located in the download directory and the code calling the function is in the root of the website. Here's the code I've tried: $test = $pdo->query("SELECT filename FROM files WHERE id =1"); $isoname = $test->fetchColumn(); $test = "download/".$isoname; $isosize = filesize($test)/1000000; It always returns zero although is returns the correct filename.
Thanks for any guidance in advance. I'm reading data from a database and writing it to an XML file. I then read the content of that file and parse the XML data. It is a little cache script so it only writes data every 180 seconds, whenever it writes data the filesize that is retrieved is still the old file size before the new data was written. This leads to an XML error... The XML error I get: XML error: no element found at line 39 $fp = fopen($file,"r") while (($data = fread($fp, filesize($file)))) { xml_parse($xml_parser, $data, feof($fp)); } fclose($fp); From my old gentoo server I run the following code with success. "/mnt/images" is a cifs mount! Code: [Select] <?php $source = '/mnt/images/1001.jpg'; $target = '/tmp/1001.jpg'; if ( file_exists($source) ) echo "file_exists: TRUE<br/>"; else echo "file_exists: FALSE<br/>"; if ( is_file($source) ) echo "is_file: TRUE<br/>"; else echo "is_file: FALSE<br/>"; if ( copy($source, $target) ) echo "copy: TRUE<br/>"; else echo "copy: FALSE<br/>"; echo "filesize source: ".filesize($source)."<br/>"; echo "filesize target: ".filesize($target)."<br/>"; ?>The output is Quote file_exists: TRUE is_file: TRUE copy: TRUE filesize source: 4715 filesize target: 4715 When I try this on my newly installed CentOS machine I get Quote file_exists: FALSE is_file: FALSE Warning: copy(/mnt/images/1001.jpg) [function.copy]: failed to open stream: Permission denied in /var/www/html/filetest.php on line 16 copy: FALSE Warning: filesize() [function.filesize]: stat failed for /mnt/images/1001.jpg in /var/www/html/filetest.php on line 21 filesize source: Warning: filesize() [function.filesize]: stat failed for /tmp/1001.jpg in /var/www/html/filetest.php on line 22 filesize target: Every function fails. Then I found that when I disable SELinux with "echo 0 > /selinux/enforce" file_exists() and copy() works. Quote file_exists: TRUE is_file: FALSE copy: TRUE Warning: filesize() [function.filesize]: stat failed for /mnt/images/1001.jpg in /var/www/html/filetest.php on line 21 filesize source: filesize target: 4715 But is_file() and filesize() still doesn't work. They all work when I run them on local files so it is somewhat related to the cifs mount. What could be the problem here? $sql = "SELECT * FROM dczcat1 ORDER BY position"; if ($result = $mysqli->query($sql)){ if ($result->num_rows > 0){ while ($row = $result->fetch_array()){ $table=$row[cattable]; echo"$table"; $scat2=$table . 2; echo"$csat"; $cat=$row[cat]; echo"$cat"; $sql="SELECT * FROM $table ORDER BY position"; echo"$sql"; if($result=$mysqli->query($sql)){ if($result->num_rows>0){ echo"Pumpkin"; while ($row = $result->fetch_array()){ echo"<br />should not be displayed if it doesn't say Pumpkin above"; $level+=1; echo"LEVEL69:$level"; echo<<<HTML <div class = "menutitles" onmouseover="document.getElementById('$table').style.display='block';document.getElementById('$scat2').style.display='block';" onmouseout="document.getElementById('$table').style.display='none';document.getElementById('$scat2').style.display='block';" > <a class="topseltxt2" href="gem.php?cat=$fullcat">$cat pos44</a><br/> <div class="contain" id="$table"> <div class="menuitems" id="$scat2"> HTML; $table=$row[cattable]; echo "$table"; $scat2= $table . 2; echo "$scat"; $cat = $row[cat]; echo "$cat"; select($cat, $table, $scat2, $mysqli, $level); } }else if($level==1){echo" <a class='topseltxt' href='gem.php?cat=$table'>$cat pos2</a><br/> "; echo"table:$table"; }else{ While($row=$result->fetch_array()){ $table=$row[cattable]; $scat2= $table . 2; $cat = $row[cat]; echo" <a class='topseltxt2' href='gem.php?cat=$table'>$cat pos3</a><br/> ";} $level-=1; } }else{ die("ERROR: Could not execute query $sql." . $mysqli->error); }echo"</div> </div> </div>"; } } }else{ die("ERROR: Query failed: $sql." . $mysqli->error); } At line 15 it says echo "Pumpkin" and below after the while loop it says "should not be displayed unless it says pumpkin above" When I run the above code it displays: should not be displayed unless it says pumpkin above No Pumpkin, how is this possible, if num_rows is greater than 0, then it should either display the word pumpkin, or it should skip everything between the {}'s shouldn't it? I don't want the while loop to run if num_rows is greater than 0, but it does and I'm sure it shouldn't be. I am getting the following error from my error handler (shown below). I don't know if it is related, but I am using register_shutdown_function in a static class. I don't even know where to start troubleshooting. Any recommendations? Thanks
An error occurred in script 'Unknown' on line 0: Unknown: Skipping numeric key 2996699736 (error no: 8 ) <?php function my_error_handler($e_number, $e_message, $e_file, $e_line, $e_vars) { $message = "An error occurred in script '$e_file' on line $e_line: $e_message (error no: $e_number)";//.print_r($e_vars,1); syslog(LOG_INFO,'my_error_handler: '.$message); } ini_set('display_errors', 1); error_reporting(E_ALL); set_error_handler("my_error_handler"); ?> Edited by NotionCommotion, 20 November 2014 - 01:29 PM. I have a registration page that mails a link to the users email. The link in the email takes the user to the activation page which sends out a welcome email and updates the database as activated if the user is not already activated. For some reason, this page is being accessed by an Amazon ip address with multiple browsers in the user_agent. Whatever this is is automatically activating my users and sending them a welcome email without them even accessing the page. The only suspect I can think of is I have a javascript snippit for google ads and also facebook on some of my pages. I don't know if they could somehow be accessing the page or not. It must be following the activation link in the mail() script I have on the registration page. I'm mailing myself the following when the activation page is accessed. I get an amazon ip, multiple browsers, and no referer. $browser = $_SERVER['HTTP_USER_AGENT']; $ip = $_SERVER['REMOTE_ADDR']; $referer = $_SERVER['HTTP_REFERER'];
|