PHP - Print A7 Size Labels With Pdf File
hi,
whats the best way to print labels. I have already tried the script from fpdf.de but i can not get my dot matrix printer (dot matrix is needed for this purpose) the correct layout. Its continuous paper, with size 110 height x 62mm width (for each label). I am not able to select a self-adjustable paper-size. so i hope to solve this with PHP / PDF if possible. anyone have experience with this? cheerz!! Similar TutorialsAnyone know how I can print a file (specifically a PDF) that is stored on the server to the clients computer with a button? I don't want them to be able to view it, just print it. I've done some research and understand that there is no way to print directly without popping up the Windows Print dialog. And that is fine. I just want them to print this file, but not no where it is or be able to type in a URL to access it. Thanks Mike Hello! I have this validation script that seems to work great until I add the size validation. I'm ready to pull my hair out! Can someone tell me what I'm doing wrong? Code: [Select] if (isset($_POST['Submit'])) { $user_id = $userdata[user_id]; $number_of_file_fields = 0; $number_of_uploaded_files = 0; $number_of_moved_files = 0; $uploaded_files = array(); $max_filesize = 5242880; // Maximum filesize in BYTES (currently 5MB). $upload_directory = dirname(__file__) . '/'.$user_id.'/'; //set upload directory if (!is_dir($upload_directory)) { mkdir($upload_directory, 0777, true); } for ($i = 0; $i < count($_FILES['images']['name']); $i++) { $number_of_file_fields++; if ($_FILES['images']['name'][$i] != '') { //check if file field empty or not $number_of_uploaded_files++; if($_FILES['images']['size'] > $max_filesize){ echo "<b class='red'>Max file size is 5MB.</b><br/>"; $sz = true; } $ext = validate_extension($_FILES['images']['name'][$i]); if (($ext == true) && ($sz == true)){ $uploaded_files[] = $_FILES['images']['name'][$i]; if (move_uploaded_file($_FILES['images']['tmp_name'][$i], $upload_directory . $_FILES['images']['name'][$i])) { $number_of_moved_files++; } }else { echo "<b class='red'>File extention error. Only .doc, .pdf, .jpg and .gif files are allowed. </b><br/>"; } } } if ($number_of_uploaded_files >= 1){ echo "Number of files submitted:<b class='red>".$number_of_uploaded_files."</b><br/>"; echo "Number of successfully uploaded files:<b class='red>".$number_of_moved_files."</b><br/><br/>"; echo "Uploaded File Name(s):<br/>" . implode('<br/>', $uploaded_files); } } As of now it results in every uploaded file returning the error "Max file size is 5MB." Hello guys and gals, I am pretty green to PHP! I have an empty array that that I am trying to put images into. The thing is I have a certain file name in the folder, I want to exclude that file. This is what I have tried, any advice would be appreciated! Code: [Select] $thumbImg[] = array(); foreach (glob($DImg) as $PImg) { if (!is_file("thumbnail.jpg")) { $thumbImg[] = "<img src=\"pathtoimage\">"; } } Later on the page I am printing it out with this. It is still including the thumbnail.jpg image. Thank you in advance!! Code: [Select] for ($i=0; $i<count($thumbImg); $i++) print $thumbImg[$i]; Hello, What im trying to do is create a file with the name "triangular_10.txt" where the number in the file name is the number the user entered. From there I want the text file to have the triangular series of numbers. So if the user enters 10, it'll display the first 10 numbers of the triangular series. So far the file name change is working. The algorithm is here that I used for PHP:http://www.codecodex.com/wiki/Calculate_a_triangle_number eg . user enters 10. Result in txt file is first 10 numbers in the triangular series = [1, 3, 6, 10, 15, 21, 28, 36, 45] This is what I have so far but Im not having any luck! At the moment its only writing the number I entered on to the txt file and nothing else! Any ideas? $number = $_POST['number-entered']; foreach ( range(1, 1000) as $i ) { $triangle_numbers[] = $i * ( $i + 1 ) / 2; } //make a file $contents = fopen('gs://a1-task22020.appspot.com/triangular_' .$number. ".txt", "w"); fwrite($contents, $number); //open the file $contents = fopen('gs://a1-task22020.appspot.com/' . $contents, 'w'); // re-open the document if you put something in it fwrite($contents, $number); fclose($contents); } }
is there a way to print the file as it appears. I want to print the HTML and PHP within a file rather than just the output. Example: File contains: <?php echo "Hello World"; ?> i would like to echo: <?php echo "Hello World"; ?> instead of just hello world which is what i get with file_get_contents() Hello, I have the following code writting IP,session, and date to a text file (it works) but I want to add a white space after the IP address. fwrite($fp, $_SERVER['REMOTE_ADDR']. $_SESSION["sess_name"]. " $dateTime\r\n"); At the moment it prints like this 16.17.51.41SESSION_ID 2011/01/23 12:53:32 thanks in advance. 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. $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??? 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! how to put code for check file size before upload in the if issertfile .the file is in format pdf or docs $targetDirg= "folder/pda-semakan/gambar/"; if(isset($_FILES['gambar'])){ $fileNameg = $_FILES['gambar']['name']; $targetFilePathg = $targetDirg . $fileNameg; //$main_tmp1 = $_FILES['surat']['tmp_name']; $moveg =move_uploaded_file($_FILES["gambar"]["tmp_name"], $targetFilePathg); }
What file size is allowed with this code?
if (@$_POST['submit'] != "") { $allowed_ext = array("gif", "jpeg", "jpg", "png", "pdf", "doc", "docs", "zip", "flv", "mp4"); $extension = end(explode(".", $_FILES["file"]["name"])); if (($_FILES["file"]["size"] < 524288000) && in_array($extension, $allowed_ext)) { I have a simple script which records search terms and writes them to an external file. I would like to limit this file size. The Use: I have a search page where people can search for PDF files. I would like to have a 'cloud tag' or list of the most recent terms searched at the bottom of the page. Here is my script which works beautifully: <?php $pattern = "/filetype:(\w+)/"; // filteype:(wildcard for word) to grab the file extension along with the word filetype: if ( $_GET['q'] == "" ) { $term = ""; } else { $term = preg_replace("$pattern", '', $_GET['q']); // get rid of the filetype parameter } $searched = $term . ", "; $fopen = fopen("searched.html", "a"); fwrite($fopen, $searched); fclose($fopen); ?> The above code grabs the search term when the SERP page is opened, and writes it to a file. I will later use phpInclude to put the contents of that file on the bottom of my search engine page. The problem is that after a million searches, this file will be huge! Question: How can I limit the file size and organize these search terms so that the most recent ones appear on the page? Hi Chaps, I'm using readfile to force the download of a file: set_time_limit(0); $file = 'monkey.gif'; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); exit; } flush(); And this works fine, however, I do have some software installation files that could be downloaded (these are in excess of 280Mb). I have checked php.ini: Quote memory_limit = 128M post_max_size = 300M But Internet Explorer hangs and then crashes. Is there a way to allow big files to download using this method, or is there another way of forcing the download, without php 'reading' the file first? I'm guessing that the problem lies with the memory_limit being smaller than the file size. Is it a good idea to increase the memory_limit to eg. 280Mb? Cheers Hello, I have this script running: Code: [Select] <?php //include("include/session.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Add an Image to Gallery</title> <link href="../../include/stylee.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="wrap"> <div id="content"> <form enctype="multipart/form-data" action="<? $_SERVER['PHP_SELF'] ?>" method="post"> <fieldset title="Add Images and Descriptions"> <legend>Add Images and Descriptions</legend> <p> Choose a file to upload: <br /> <input name="image" type="file" /> </p> <p>Give the Image a Short Description<br /> <input name="ushortdesc" type="text" size="60" maxlength="75" /> </p> <p>Give the Image a Long Description<br /> <textarea name="ulongdesc" cols="60" rows="10"></textarea> </p> <p>Where does the Image Link to?<br /> <input name="uimglink" type="text" value="http://www.yoursite.com/yourstore/or..." size="60" /> </p> <p> <input type="submit" name="upload" value="Upload" /> </p> </fieldset> </form> </div> <div id="report"> <?php //function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth ) //{ // // open the directory // $dir = opendir( $pathToImages ); // // // loop through it, looking for any/all JPG files: // while (false !== ($fname = readdir( $dir ))) { // // parse path for the extension // $info = pathinfo($pathToImages . $fname); // // continue only if this is a JPEG image // if ( strtolower($info['extension']) == 'jpg' ) // { // echo "Creating thumbnail for {$fname} <br />"; // // // load image and get image size // $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" ); // $width = imagesx( $img ); // $height = imagesy( $img ); // // // calculate thumbnail size // $new_width = $thumbWidth; // $new_height = floor( $height * ( $thumbWidth / $width ) ); // // // create a new temporary image // $tmp_img = imagecreatetruecolor( $new_width, $new_height ); // // // copy and resize old image into new image - for gd-1 version // //imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); // //randys alteration for gd-2 version // imagecopyresampled( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); // // // save thumbnail into a file // imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" ); // } // } // // close the directory // closedir( $dir ); //} // // call createThumb function and pass to it as parameters the path //// to the directory that contains images, the path to the directory //// in which thumbnails will be placed and the thumbnail's width. //// We are assuming that the path will be a relative path working //// both in the filesystem, and through the web for links //createThumbs("images/","images/thumbs/",100); //echo "<h2>All Done!</h2>"; if(isset($_POST['upload'])) { $size = 50; // the thumbnail height $filedir = 'images/'; // the directory for the original image $thumbdir = 'thumbs/'; // the directory for the thumbnail image $prefix = 'thumb_'; // the prefix to be added to the original name $maxfile = '2100000'; $mode = '0666'; $userfile_name = $_FILES['image']['name']; $userfile_tmp = $_FILES['image']['tmp_name']; $userfile_size = $_FILES['image']['size']; $userfile_type = $_FILES['image']['type']; if (isset($_FILES['image']['name'])) { $uimg = $filedir.$userfile_name; $uimg_thumb = $thumbdir.$prefix.$userfile_name; move_uploaded_file($userfile_tmp, $uimg); chmod ($uimg, octdec($mode)); $sizes = getimagesize($uimg); $aspect_ratio = $sizes[0]/$sizes[0]; if ($sizes[0] <= $size) { $new_width = $sizes[0]; $new_height = $sizes[0]; }else{ $new_height = $size; $new_width = abs($new_height/$aspect_ratio); } $destimg=ImageCreateTrueColor($new_width,$new_height) or die('Problem In Creating image'); $srcimg=ImageCreateFromJPEG($uimg) or die('Problem In opening Source Image'); if(function_exists('imagecopyresampled')) { imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); }else{ Imagecopyresized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); } ImageJPEG($destimg,$uimg_thumb,90) or die('Problem In saving'); imagedestroy($destimg); } echo ' <a href="'.$uimg.'"> <img src="'.$uimg_thumb.'" width="'.$new_width.'" heigt="'.$new_height.'"> </a>'; } ?> </div> </body> </html> Works great, except when I upload a 400kb or larger file... Is there some kind of limit to the ability of the GD library? Anyone have a work around? Thanks! hello anyone can help me to reduce image file size(reduce quality of images) using php ? Ok so I have someone needing me to write a php page(s) to basically check the current size of a file in a directory and display the current size and max allocated size then create a dynamically changing image to reflect those parameters(i.e. pise chart, bar graph, etc.) all called to an intranet page. I work at a business where we upload OS images to a server file but that file is only allocated so much space. The problem we are running into is that we do not know when the space is full until all of our uploads fail. We are attempting to create a visual representation of that space so that we know when to purge the space of the old temporary images. I dont even know where to start on this .. would someone please point me in the direction of some code that would get me started on building this project? I have exhausted my efforts on Google and other PHP pages.. I am new to PHP so I may already be in over my head but I am adventurous and will try anything. Thanx in advance Khaelyx I've got a basic form for users on the site to fill out a form and upload a single image which is resized and saved to a directory on the server. I've tried the form numerous times and with images usually under 1MB the form successfully submits, data is queried and the image uploaded is resized and saved. However, recently I tried uploading larger sized images (1.2mb, 2.4mb, 3mb) and the script would seem to break. It wouldn't query any information, save any images, etc. If you check my code attached, I have errors ready to output at all levels and not even any errors show up. When I hit submit after attempting to upload a larger file usually over 1MB, the page refreshes back to PHP_SELF as if it submitted but returns absolutely no message, alert or error and the form which was on the page is now gone. I checked my PHP.ini file and my max file size upload is set at 32mb. Is there anything else with file size restrictions that I could be missing that is allowing this script to crash without even sending me any errors? if(!empty($_POST['submitFeature'])) { // set variables $featurename = mysql_real_escape_string($_POST['featurename']); $featuredesc = mysql_real_escape_string($_POST['featuredesc']); $name = mysql_real_escape_string($_POST['name']); $email = mysql_real_escape_string($_POST['email']); $email2 = mysql_real_escape_string($_POST['email2']); $age = mysql_real_escape_string($_POST['age']); $city = mysql_real_escape_string($_POST['city']); $state = mysql_real_escape_string($_POST['state']); $src = $_FILES['featureupload']['tmp_name']; $featuresize = $_FILES['featureupload']['size']; $limitsize = 1000000; // 1 - A. REQUIRED FIELDS VERIFICATION if(!empty($featurename) && !empty($name) && !empty($email) && !empty($email2) && !empty($city) && !empty($state) && ($email == $email2) && !empty($_FILES['featureupload']['tmp_name']) && ($featuresize < $limitsize)) { // 2 - A. SANITIZE AND VALIDATE EMAIL $email = filter_var($email, FILTER_SANITIZE_EMAIL); if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { print ' <ul class="errorlist"> <li class="alert">Error!</li> <li>Invalid Email Address</li> </ul> '; } else { // 3 - A. VALIDATE IMAGE EXTENSION // verify that image uploaded is proper extension $fname = strtolower($_FILES['featureupload']['name']); // grab uploaded image's filename and lowercase the extension (ex: .JPG) if(preg_match('/[.](jpg)|(gif)|(png)$/', $fname)) { // set image variables $path_image = 'submissions/'; $final_width_of_image = 550; $randomappend=rand(0000,9999); // generate random number to append to filename $src = $_FILES['featureupload']['tmp_name']; // grab the src for where the image is temporarily held $filefull = $randomappend . $fname; // initiate new file name for submission's full image $target = $path_image . $filefull; // set variable for submission image's new location with appended name $path_image_thumb = 'submissions/thumbs/'; $final_width_of_thumb = 166; $final_height_of_thumb = 120; $filethumb = $randomappend . $fname; // initiate new file name for submission's thumbnail $target_thumb = $path_image_thumb . $filethumb; // set variable for thumbnail's new location with appended name move_uploaded_file($src, $target); if(preg_match('/[.](jpg)$/', $filefull)){ $img = imagecreatefromjpeg($path_image . $filefull); } else if (preg_match('/[.](gif)$/', $filefull)){ $img = imagecreatefromgif($path_image . $filefull); } else if (preg_match('/[.](png)$/', $filefull)){ $img = imagecreatefrompng($path_image . $filefull); } // FULL SIZE IMAGE $ox = imagesx($img); $oy = imagesy($img); $imgx = $final_width_of_image; $imgy = floor($oy * ($final_width_of_image / $ox)); $imgm = imagecreatetruecolor($imgx, $imgy); imagecopyresampled($imgm, $img, 0,0,0,0,$imgx,$imgy,$ox,$oy); if(!file_exists($path_image)){ if(!mkdir($path_image)){ die("There was a problem."); } } imagejpeg($imgm, $path_image . $filefull, 80); // END FULL SIZE IMAGE // THUMBNAIL $tox = imagesx($img); $toy = imagesy($img); $tx = $final_width_of_thumb; $ty = $final_height_of_thumb; $tm = imagecreatetruecolor($tx, $ty); imagecopyresampled($tm, $img, 0,0,0,0,$tx,$ty,$tox,$toy); if(!file_exists($path_image_thumb)){ if(!mkdir($path_image_thumb)){ die("There was a problem."); } } imagejpeg($tm, $path_image_thumb . $filethumb, 80); // END THUMBNAIL // query the actual post forms $q = "INSERT INTO submissions (id, name, age, email, city, state, country, featurename, featuredesc, featureimg, featurethumb, postdate, approved) VALUES ('', '$name', '$age', '$email', '$city', '$state', '', '$featurename', '$featuredesc', '$target', '$target_thumb', NOW(), 'NO')"; $r = mysql_query($q); if($r) { echo '<script language="JavaScript">'; echo 'alert("Successfully added a submission.")'; echo '</script>'; } else { echo '<script language="JavaScript">'; echo 'alert("Submission was not added. Please try again.")'; echo '</script>'; } } else { echo '<script language="JavaScript">'; echo 'alert("Unacceptable image extension.")'; echo '</script>'; } // 3 - B. VALIDATE IMAGE EXTENSION } // 2 - B. END SANITIZE AND VALIDATE EMAIL // 1 - B. END REQUIRED FIELDS VERIFICATION } else { print ' <ul class="errorlist"> <li class="alert">Please fill out the required fields.</li> '; if (empty($name)) { echo ' <li>* Full Name</li>' . "\n"; $errorname = 'TRUE'; } if (empty($email)) { echo ' <li>* Email</li>' . "\n"; $erroremail = 'TRUE'; } if (empty($email2)) { echo ' <li>* Confirm Email</li>' . "\n"; $erroremail2 = 'TRUE'; } if (empty($city)) { echo ' <li>* City</li>' . "\n"; $errorcity = 'TRUE'; } if (empty($state)) { echo ' <li>* State</li>' . "\n"; $errorstate = 'TRUE'; } if ($email != $email2) { echo ' <li>* Emails do not match.</li>' . "\n"; } if (empty($_FILES['featureupload']['tmp_name'])) { echo ' <li>* You did not upload a feature.</li>' . "\n"; $errorfile = 'TRUE'; } if (empty($featurename)) { echo ' <li>* Feature Name</li>' . "\n"; $errorfeature = 'TRUE'; } if ($featuresize >= $limitsize) { echo ' <li>* File size is too large.</li>' . "\n"; } print ' </ul> '; } // 1 - B. END REQUIRED FIELDS ERROR CODES } I am trying to check to see if a file size is acceptable before an upload but cant seem to get the right result no matter what i do. if i have my if statement below coded like this Code: [Select] if($_FILES["upload"]["size"] < 1024000){ echo'entered if statement<br />'; } else{ echo'entered else statement<br />'; } Then i always am entereing the if statememnt but if i have my if statement like this Code: [Select] if($_FILES["upload"]["size"] > 1024000){ echo'entered if statement<br />'; } else{ echo'entered else statement<br />'; } then i always seem to enter the else staement. I have tried with a VIREITY of differnt size files some from like 2kb to 10mb... i believe somewhere near the > or < is my problem but i dont seem to see it |