PHP - Separating Size From Id+size Number
Hi there,
In a string for a shopping cart I am storing both the item id and the item size selected in a number like this 12s1 where 12 is the id and 1 is the size. How can I separate these from one another again? I'm guessing it's to do with expand() ? Thanks, Jack Similar Tutorialscould someone help in how to resize a uploaded image size, say if someone is uploading a 1mb photo to my server, i wish for it to become 100kb and also resize its width and height? here is my code Code: [Select] //////////////////////////////////////uploader else if($action=="uploader") { echo "Upload your picture and copy the link <br/>after uploading to user it at gallery.<br/><br/>"; echo "<form method=\"post\" enctype=\"multipart/form-data\" action=\"index.php?action=uploaded&sid=$sid\">"; echo "Choose Pictu <br />"; echo "<input name=\"uploaded\" type=\"file\" /><br /><br />"; echo "<input type=\"submit\" value=\"Upload\" />"; echo "</form><br/>"; echo "<p align=\"center\">"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } //////////////////////////////////////uploader else if($action=="uploaded") { $blacklist = array(".php", ".php.jpg", ".php.jpeg", ".php.gif", ".php.png", ".phtml", ".php3", ".php4"); foreach ($blacklist as $item) { if(preg_match("/$item\$/i", $_FILES['uploaded']['name'])) { echo "<p align=\"center\">"; echo "Oops sorry we do not allow those files.<br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; exit; } } $target = "../images/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if (file_exists("../images/" . $_FILES["uploaded"]["name"])) { echo "<p align=\"center\">"; echo $_FILES["file"]["name"] . "Oops file name already exists<br/> kindly rename your picture and upload again. <br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; }else{ //This is our size condition if ($uploaded_size > 25600){ echo "Your file is too large. We have a 25kb limit.<br/>"; $ok=0; } $types = array('image/jpeg', 'image/gif', 'image/png'); if (in_array($_FILES['uploaded']['type'], $types)) { // file is okay continue } else { $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0){ echo "<p align=\"center\">"; Echo "Sorry your file was not uploaded.<br/> It may be the wrong filetype. <br/>We only allow JPG, GIF, and PNG filetypes.<br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } //If everything is ok we try to upload it else{ if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){ echo "<p align=\"center\">"; echo "The file ". basename( $_FILES['uploadedfile']['name']). " Picture uploaded successfully.<br/><br/><b>$target <br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } else{ echo "<p align=\"center\">"; echo "Sorry, there was a problem uploading your file.<br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } } } } I have a problem that occurred only recently, apparently by some change my webhost made on the server. Some time ago I wrote a script that simulates a Poedit-type editor. The script has about 1500 textareas (the translation fields) with unique names, dynamically generated. All worked fine. Now suddenly I get errors (see below) when I use more than 1000 textareas. It is not a problem of $_POST size, if happens also with empty textareas. I will show here a simple php test file that I called testta.php, which creates the same error as my much more complicated real script: Code: [Select] <?php if(isset($_POST['test'])) { echo 'The textareas were posted successfully!<br>'; } $max = 1500; echo '<form action="testta.php" method="POST">'; echo '<input type="submit" name="test" value="Submit"><br>'; for($i=0; $i < $max; $i++) { echo '<textarea name="test'.$i.'">name is test'.$i.'</textarea><br>'; } echo '</form>'; ?> The error message generated in the browser: 500 Server Error: A misconfiguration on the server caused a hiccup. Check the server logs, fix the problem, then try again. From the Apache log file: [Sat Apr 28 12:47:48 2012] [error] [client 93.172.175.50] Premature end of script headers: testta.php, referer: http://****/*****/testta.php (stars added for privacy) When $max is set to a number < 1000 it works. On the web I have only found answers that deal with max size of posts, but as I mentioned that is not my case. My webhost can't help me out either. Until last Friday all worked fine. Does anyone know what server setting could create this problem? Thanks in advance, Kathy i need help gettig the size of a directory Hello again How to convert size from taken from sql as the numbers and converted to MB in php? Hello: Hoping someone can help me figure this out... I am resizing a photo/thumbnails with GD (I think that's the correct term) upon uploading. Works fine but the one thing I can't figure out is how to scale the height proportionate with the width. Meaning, I have the width set to 690px, and the height set to 500px. It is making the images look squished. What I would like to do is have a set width (like 690px), but have the height scale down proportionalety. Or, can I just remove the height (although I tried that and it did not work). This is the code: Code: [Select] // Let's get the Thumbnail size $size = GetImageSize( $images_dir."/".$filename ); if($size[0] > $size[1]) //{ //$thumbnail_width = 100; //$thumbnail_height = (int)(100 * $size[1] / $size[0]); //} //else //{ //$thumbnail_width = (int)(100 * $size[0] / $size[1]); //$thumbnail_height = 100; //} { //$thumbnail_width = 690; //$thumbnail_height = (int)(500 * $size[1] / $size[0]); $old_width = $size[0]; $old_height = $size[1]; $thumbnail_width = 690; $thumbnail_height = ($old_height * $thumbnail_width / $old_width); } else { $thumbnail_width = (int)(690 * $size[0] / $size[1]); $thumbnail_height = 500; } // Build Thumbnail with GD 1.x.x, you can use the other described methods too $function_suffix = $gd_function_suffix[$filetype]; $function_to_read = "ImageCreateFrom".$function_suffix; $function_to_write = "Image".$function_suffix; // Read the source file $source_handle = $function_to_read ( $images_dir."/".$filename ); if($source_handle) { // Let's create an blank image for the thumbnail //$destination_handle = ImageCreate ( $thumbnail_width, $thumbnail_height ); $destination_handle = imagecreatetruecolor( $thumbnail_width, $thumbnail_height ); // Now we resize it ImageCopyResized( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1] ); } // Let's save the thumbnail $function_to_write( $destination_handle, $images_dir."/tb_".$filename ); ImageDestroy($destination_handle ); // $result_final .= "<img src='".$images_dir. "/tb_".$filename."' style='margin-right: 20px; width: 100px;' />"; Anyone have any ideas on this? Thanks much. I am able to get directory size of folder inside folders owned by me but I need to get folder size of a root owned folder. Is it possible to do this? Thanks in advance! Hi I know that maximum size of one cookie is 4Kb.. That is kilobytes right? and not kilobit? And a byte is 8 bits right? So if I have "Hello" in my cookie thats 5 characters which means the cookie is 5 x 8 = 40 bit which is again 5 bytes (?). Does this mean that I can have a maximum of 4000 characters in my cookie? Or did I miss something here? Thanks Hi, I'm using the script below to that allows a user to upload a photo, which then appears on the page as a thumbnail, the image can be clicked and opens up in a lightbox image pop up. All this works fine except the images are not resizing. I.e if a a picture is 1024px wide, before upload - it stays that size on the server. I need it to compress down to around 600px wide and have the KB of the file reduced. I know that I should be using GD library to do this but not sure how to implement it. The script I am using is he ############################################################################################## function upload($user_id,$fileid) ############################################################################################## { global $db; $maxsize = $_POST['MAX_FILE_SIZE']; if(is_uploaded_file($_FILES['userfile']['tmp_name'][$fileid])) { if($_FILES['userfile']['size'][$fileid] < $maxsize) { $imgData = addslashes(file_get_contents($_FILES['userfile']['tmp_name'][$fileid])); $size = getimagesize($_FILES['userfile']['tmp_name'][$fileid]); $sql_query = "SELECT * FROM user_images WHERE image_id = '999999999999999999'"; if(mysqli_num_rows(mysqli_query($db, $sql_query)) > 0) { $sql_query = "UPDATE user_images SET image_type = '{$size['mime']}', image = '{$imgData}', image_size = '{$size[3]}', image_name = '{$_FILES['userfile']['name'][$fileid]}' WHERE image_id = '$user_id'"; } else { $sql_query = "INSERT INTO user_images ( image_type ,image, image_size, image_name) VALUES ('{$size['mime']}', '{$imgData}', '{$size[3]}', '{$_FILES['userfile']['name'][$fileid]}')"; } if(!mysqli_query($db,$sql_query)) { echo '<div class="error">Unable to upload file</div>'; } else { $return = mysqli_insert_id($db); } } else { echo '<div>File exceeds the Maximum File limit. Skipping uploading of image.</div> <div>Maximum File limit is '.$maxsize.'</div> <div>File '.$_FILES['userfile']['name'][$fileid].' is '.$_FILES['userfile']['size'][$fileid].' bytes</div> <hr />'; } } return $return; }//END - upload() ############################################################################################## function imageResize($width, $height, $target) ############################################################################################## { //protect function if image sizes not set (i.e. image doesn't exist in database) if((!isset($width)) || (!isset($height))) { $width = '1'; $height = '1'; } //if trying to resize an image that is much smaller than target...essentially do nothing and keep the original sizing elseif(($width < $target) && ($height < $target)) { } else { //takes the larger size of the width and height and applies the formula accordingly...this is so this script will work dynamically with any size image if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); } //gets the new value and applies the percentage, then rounds the value $width = round($width * $percentage); $height = round($height * $percentage); } //returns the new sizes in html image tag format... return "width=\"$width\" height=\"$height\""; }//END - imageResize ############################################################################################## $file="../myclients/clients/".$company_name."/Download/".$file_name; $size = filesize($path); // not working i try with function also function formatbytes($file, $type) { switch($type){ case "KB": $filesize = filesize($file) * .0009765625; // bytes to KB break; case "MB": $filesize = (filesize($file) * .0009765625) * .0009765625; // bytes to MB break; case "GB": $filesize = ((filesize($file) * .0009765625) * .0009765625) * .0009765625; // bytes to GB break; } if($filesize <= 0){ return $filesize = 'unknown file size';} else{return round($filesize, 2).' '.$type;} } echo formatbytes($file, "KB"); uploaded file size is 488 kb but it showing "unknown file size" please help me. i want to display the size of a file but i round it off to the nearest kb. I am using... ($_FILES["file"]["size"]/1024/1024)."mb" i am geting it return something like this.... 1.0313243865967mb and i want it to be more like 1.03mb any idears??? What's the maximum file size I can upload through a regular form ? If it's server dependant, how do I find out my max ? I tried to handle a 550MB file (on localhost) - I only wanted to show the filename, but it hung up for about 10secs, then returned nothing. rating_bar($rows['id'],'6','static')." Show a star rating but the stars are to big. How can I change the size of the rating_bar, like I change the font size? echo "<TD style='font-size: 10px;' ALIGN=justify width=50% height=10 scope='row'><p>Please rate</p>". rating_bar($rows['id'],'6','static')."</TD>"; Font size GD Library Hi All I'm trying to create a font tester - http://www.ttmt.org.uk/fonts/index.php (this demo doesn't use the font I'm using.). I'm using the GD library to create images of the text. I'm not happy with the quality of the fonts at small sizes. I've tried everything to fix it but nothing is working. One suggestion I had was to create the fonts larger then reduce the size of the image. Can anyone offer any advise how I might do this? Code: [Select] <?php header('Content-Type: image/png'); $im = imagecreatetruecolor(1000, 200); $gray = imagecolorallocate($im, 240, 240, 240); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 1000, 199, $gray); $text = $_GET['text']; $textSize = $_GET['size']; $font = $_GET['font']; imagefttext($im, $textSize, 0, 15, 160, $black, $font, $text); imagepng($im); imagedestroy($im); ?> Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>untitled</title> <style type="text/css"> *{margin:0;padding:0;} #wrap{margin:20px 0 0 20px;} h1{margin:0px 0 20px 0;clear:both;} h2{font-size:1.1em;margin:15px 0 5px 0;} #top{padding:0 0 20px 0;} form{margin:0 0 20px 0;} </style> </head> <body> <div id="wrap"> <form action="index.php" method="post"> <!--<input type="text" name="text" value="<?php echo $_POST['text'];?>" />--> <select name="text" > <option value="<?php echo $_POST['text'];?>">Text</option> <option value="ABCDEFGHIJKLMNOPQRSTUVWXYZ">ABCDEFGHIJKLMNOPQRSTUVWXYZ</option> <option value="abcdefghijklmnopqrstuvwxyz">abcdefghijklmnopqrstuvwxyz</option> <option value="0123456789">0123456789</option> </select> <select name="size"> <option value="<?php echo $_POST['size'];?>">Size</option> <option value="10">10</option> <option value="12">12</option> <option value="14">14</option> <option value="18">18</option> <option value="24">24</option> <option value="30">30</option> <option value="38">38</option> <option value="42">42</option> <option value="50">50</option> <option value="60">60</option> <option value="80">80</option> <option value="100">100</option> </select> <input type="submit" name="submit" value="Set →" /> </form> <div id="top"> <?php $theFont="corbelb.ttf"; if(!empty($_POST['submit'])){ $myText = $_POST['text']; $mySize = $_POST['size']; echo '<img src="imageftt.php?text='.$myText.'&size='.$mySize.'&font='.$theFont.'">'; }else{ $myText = "Handgloves"; $mySize = 24; echo '<img src="imageftt.php?text='.$myText.'&size='.$mySize.'&font='.$theFont.'">'; } ?> </div> </div> </body> </html> Hi Im building a file hosting script and need to do two things. I have two sets of users FREE and PAID. Both users can upload files to thier own folder, but free users can upload only 2gb of files and paid users can upload 10gb. Is there anyone who could give some pointers on how i can: Allow different folder quotas/sizes for both users Stop both users exceeding their quota. inform them when thier quota is full. Hope someone can give me help on this thanks Lee I need to check a file's size with php and ssh. Everything I've seen online for remote files uses curl and port 80. I'll be checking a LAN computer that isn't running a webserver, but is running an SSH server. How can I do this? I've tried this: Code: [Select] <?php $tomorrow = date ('n-j-y'); echo system(ssh root@192.168.2.169 ls -lah "/MacRadio X/WMIS Logs/WMIS $tomorrow Log" | awk {print $5}); ?> but it didn't work. I got a T_VARIAABLE error. This was the same command I used right from the command line, and it worked. I'll also need to add a check to the file size, and if it's less than 175K, send me an email...but I'll work on that after I have the first part working. Thanks! This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=347531.0 I use a simple php code (taken from php.net example) to resize an image Code: [Select] list($width, $height) = getimagesize($filename); $new_height = $height / $width * 400; $image_p = imagecreatetruecolor(400, $new_height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, 400, $new_height, $width, $height); imagejpeg($image_p, "new.jpg"); Here, we create a blank image and merge it with the resized image. I wonder if it is the simplest way to resize and save an image. Is it really necessary to create a blank background image? Is there a way I can get the .jpg file in kilobytes from a remote url and check it to make sure it does not exceed 40 kilobytes before it saves the remote url into my database? When you try and upload files using a size limiting feature, when you consider $_FILES['form_element']['size'] what actually is this measured in again? I seem to have forgotten what it's actually measured in, if I was to say a limit on $_FILES['myform_file_upload']['size'] < 20000, what does the 20000 actually mean? Any help is appreciated, Jeremy. |