jakebur01 Posted March 1, 2010 Share Posted March 1, 2010 Hello, I just moved my image uploader script from a windows server to linux. Somehow I guess php was grabbing the post variables automatically on the windows server. Any way, my problem is that it is not reading the file on the upload page. It throws the error "Error: No File Specified". I tried putting $img1_name=$_FILES['img1_name']; then I was getting a file extension error. form <FORM ACTION="/imageuploader/image_receiver.php" METHOD="POST" NAME="udata" ENCTYPE="multipart/form-data"> <FONT SIZE=-1> <p class="m_text">Your post may not contain any foul content! <br />Your ip address is <?php echo $ip; ?> and will be stored for our records.</p> <p><B>Enter Photo Upload Code:</B> <INPUT TYPE="password" NAME="pass" SIZE=10> <img src="images/secretcode.jpg" alt="secret code" width="150" height="45"></p> <p><B>Enter File Name:</B> <INPUT TYPE="file" NAME="img1_name" id="img1_name" SIZE="30"> </p> <p><B>Name:</B> <label> <input name="name" type="text" id="name" value="" size="30" maxlength="30"> </label> </p> <p><B>Description:</B> <label> <input name="description" type="text" id="description" value="" size="50" maxlength="80"> </label> </p> <p> <INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Upload File"> </p> </FORM> image upload page <?php $name = $_POST['name']; $description = $_POST['description']; $pass = $_POST['pass']; ////////////////// Image Uploader Receiver /////////////////// // Copyright (c) 2003 CarTest Software, All Rights Reserved // ////////////////////////////////////////////////////////////// include "image_receiver_header.html"; require "image_config.php"; // check password if($require_password_to_upload && $pass != $password) die("Invalid Password Entered"); // file specified? if($img1_name == "") die("Error: No File Specified"); // allowed file types $ext1=".jpg"; $ext2=".gif"; $ext=strtolower(substr($img1_name, strlen($img1_name)-4)); $imageType=0; if($ext == $ext1) { $imageType=1; } elseif ($ext == $ext2) { $imageType=2; } else { die("Error: $ext1 or $ext2 File Types Only Please"); } $ran = rand () ; $img1_name = $ran.date(MDY)."$ext"; $db = new mysqli('localhost', 'tuser', 'user', 'table'); if (mysqli_connect_errno()) { echo 'Error: Could not connect to database. Please try again later.'; exit; } $ip=$_SERVER['REMOTE_ADDR']; $url= "http://www.mysite.com/imageuploader/uploads/$img1_name"; $query = "insert into extremephoto values ('0', '$url', '$name', '$description', '$ip', 'no')"; $result = $db->query($query) or die(mysqli_error()); if ($result) echo $db->affected_rows.' message inserted into database. '; $db->close(); // file size limit if($file_size_limit >= 0 && $img1_size > $file_size_limit) die ("File Size Exceeds $file_size_limit Byte Limit"); // replace certain characters with _ $img1_name=strtr($img1_name," ","_"); $img1_name=strtr($img1_name,"#","_"); $img1_name=strtr($img1_name,"/","_"); $img1_name=strtr($img1_name,"\\","_"); // need to escape the backslash character $img1_name=strtr($img1_name,"%","_"); // check if file already exists $fullpath_to_image=$path_to_images.$img1_name; if(file_exists($fullpath_to_image)) { die("Error: File Already Exists"); } // check for banned ip if(strlen($banned_ip_list_file_name) > 0) { $fo=fopen($banned_ip_list_file_name,"rt"); if($fo != 0) { while(!feof($fo)) { $ipaddr=fgets($fo); $ipaddr=substr($ipaddr, 0, strlen($ipaddr)-1); // strip \n character at end automatically read in $l=strlen($ipaddr); if($l > 0 && substr($REMOTE_ADDR, 0, $l) == $ipaddr) die("Uploader Closed"); } $fc=fclose($fo); } } // full paths to thumbnails if(strlen($path_to_thumbnails) > 0 && $thumbnail_width > 0 && $thumbnail_height > 0) { $fullpath_to_thumbnail=$path_to_thumbnails.$img1_name; $thumbs=true; } else { $thumbs=false; } // save image, @ symbol means ignore errors generated copy($img1 , $fullpath_to_image) or die("Error: Couldn't Upload Your File"); // add file name, ip address, and timestamp to log file // open, lock the file, seek file pointer to end, write record, close (unlocks) if(strlen($upload_log_file_name) > 0) { $fo=fopen($upload_log_file_name,"a+t"); $fl=flock($fo,LOCK_EX); $fs=fseek($fo, 0, SEEK_END); $fw=fputs($fo,$img1_name." ".$REMOTE_ADDR." ".date("M d Y, H:i")."\n"); $fc=fclose($fo); } // resize? if($max_image_width > 0 && $max_image_height > 0) { $resize=true; } else { $resize=false; } // resize image to (maxwidth x maxheight) preserving existing aspect ratio (unless already smaller) and resave with fixed compression level // and create thumbnail .jpeg only if($imageType == 1) { // create images if($thumbs) $imgthumb=@imageCreateTrueColor($thumbnail_width, $thumbnail_height) or die ("Error: Cannot Create Thumbnail Image"); // need an image resource for resizing, do this even if not resizing to check for valid jpeg format file $im=@imageCreateFromJpeg($fullpath_to_image); if($im === false) { @unlink($fullpath_to_image) or die("Error: Improper Jpeg Image, Couldn't Delete File"); die ("Error: Improper Jpeg Image, Image Deleted"); } // original image size $sx=imageSx($im); $sy=imageSy($im); if($thumbs) { // use Resampled rather than Resize otherwise thumbnail is terrible @imageCopyResampled($imgthumb, $im, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $sx, $sy) or die("Error: Error Resizing for Thumbnail"); // write to subdirectory with same name as large file @imageJpeg($imgthumb, $fullpath_to_thumbnail, $image_quality) or die("Error: Couldn't Save Jpeg Thumbnail"); } if($resize) { // delete initial image @unlink($fullpath_to_image) or die("Error: Couldn't Delete Original Image"); // resize original image if($sx > $max_image_width || $sy > $max_image_height) { $rx=round($max_image_width); $ry=round($rx/($sx/$sy)); if($ry > $max_image_height) { $ry=round($max_image_height); $rx=round($ry*($sx/$sy)); } $imresized=@imageCreateTrueColor($rx, $ry) or die ("Error: Cannot Create Resized Image"); @imageCopyResampled($imresized, $im, 0, 0, 0, 0, $rx, $ry, $sx, $sy) or die("Error: Error Resizing Image"); @imageJpeg($imresized, $fullpath_to_image, $image_quality) or die("Error: Couldn't Save Resampled/Resized Jpeg"); } else { @imageJpeg($im, $fullpath_to_image, $image_quality) or die("Error: Couldn't Save Resampled Jpeg"); } } } else { // image size only for .gif $as = Array(); $as=getImageSize($fullpath_to_image); $sx=$as[0]; // image width $sy=$as[1]; // image height } echo "<BR><BR><BR>"; echo "<H1>File Upload Successful!</H1>"; //echo "<P>Successfully Sent: $img1_name, a $img1_size byte, $sx x $sy (original size) file with the extension type of $img1_type"; echo "<BR>"; if($resize && $imageType == 1) { $newsize=filesize($fullpath_to_image); if($sx > $max_image_width || $sy > $max_image_height) { // echo "<P>Image was resized to $rx x $ry and recompressed to $newsize bytes<BR>"; } else { //echo "<P>Image was recompressed to a file size of $newsize bytes<BR>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/ Share on other sites More sharing options...
inversesoft123 Posted March 1, 2010 Share Posted March 1, 2010 It is likely a PHP file upload limit configuration. check your php.ini and increase your file upload limit. If you do not have a root access. ask your host to do so. It looks like in php.ini ; Maximum allowed size for uploaded files. upload_max_filesize = 2M Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1019903 Share on other sites More sharing options...
jakebur01 Posted March 1, 2010 Author Share Posted March 1, 2010 I doubt that. The jpeg I was trying to upload is 8kb. Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1019906 Share on other sites More sharing options...
inversesoft123 Posted March 1, 2010 Share Posted March 1, 2010 I doubt that. The jpeg I was trying to upload is 8kb. $ext1=".jpg"; $ext2=".gif"; add $ext3=".jpeg"; for test purpose you can upload jpg file on server Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1019909 Share on other sites More sharing options...
jakebur01 Posted March 1, 2010 Author Share Posted March 1, 2010 I have tried all three extensions. I think the problem may be that I am not properly posting the file to the page. I am currently using: $img1_name = $_FILES['img1_name']; Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1019913 Share on other sites More sharing options...
Wolphie Posted March 1, 2010 Share Posted March 1, 2010 Please bear in mind that $_FILES is a multi-dimensional array. http://www.w3schools.com/PHP/php_file_upload.asp $_FILES['img1_name']['size'] $_FILES['img1_name']['name'] $_FILES['img1_name']['type'] $_FILES['img1_name']['tmp_name'] $_FILES['img1_name']['error'] etc... I can't see anywhere in your code where you use these. Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1019916 Share on other sites More sharing options...
inversesoft123 Posted March 1, 2010 Share Posted March 1, 2010 I have tried all three extensions. I think the problem may be that I am not properly posting the file to the page. I am currently using: $img1_name = $_FILES['img1_name']; is the a full code designed by Copyright © 2003 CarTest Software, All Rights Reserved somthing is missing if ($HTTP_POST_VARS['submit']) { /////////////code } Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1019918 Share on other sites More sharing options...
inversesoft123 Posted March 1, 2010 Share Posted March 1, 2010 Please bear in mind that $_FILES is a multi-dimensional array. http://www.w3schools.com/PHP/php_file_upload.asp $_FILES['img1_name']['size'] $_FILES['img1_name']['name'] $_FILES['img1_name']['type'] etc... I can't see anywhere in your code where you use these. yap even that Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1019919 Share on other sites More sharing options...
Wolphie Posted March 1, 2010 Share Posted March 1, 2010 Try setting up some error handling, add a var_dump() or a die() somewhere in the script to see where it's failing. Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1019923 Share on other sites More sharing options...
jakebur01 Posted March 1, 2010 Author Share Posted March 1, 2010 Please bear in mind that $_FILES is a multi-dimensional array. http://www.w3schools.com/PHP/php_file_upload.asp $_FILES['img1_name']['size'] $_FILES['img1_name']['name'] $_FILES['img1_name']['type'] $_FILES['img1_name']['tmp_name'] $_FILES['img1_name']['error'] etc... I can't see anywhere in your code where you use these. This is what I was looking for. How can I store all of these into the $img1_name variable? Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1019926 Share on other sites More sharing options...
jakebur01 Posted March 1, 2010 Author Share Posted March 1, 2010 I tried this: $img1_name=$_FILES['img1_name']['size']; $img1_name.=$_FILES['img1_name']['name']; $img1_name.=$_FILES['img1_name']['type']; $img1_name.=$_FILES['img1_name']['tmp_name']; $img1_name.=$_FILES['img1_name']['error']; But,.... I get this: Error: .jpg or .gif File Types Only Please Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1019927 Share on other sites More sharing options...
Wolphie Posted March 1, 2010 Share Posted March 1, 2010 Then there's a problem with your error handling in your code, rather than a server issue. Also, bear in mind that it won't work if you concatenate all of the elements into a single string. $img1_name = $_FILES['img1_name']['name']; // This must remain just for the name, not size etc.. Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1019929 Share on other sites More sharing options...
PFMaBiSmAd Posted March 1, 2010 Share Posted March 1, 2010 The $img1_name variable is what is in $_FILES['img1_name']['name']; The $img1_size variable is what is in $_FILES['img1_name']['size']; The $img1 variable is what is in $_FILES['img1_name']['tmp_name]; It's not a matter of trying to store all those values into $img1_name, it's a matter of correcting your code to use each value where it needs to be. That code is almost 8 years out of date. Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1019933 Share on other sites More sharing options...
jakebur01 Posted March 1, 2010 Author Share Posted March 1, 2010 Got it~ Thank you much! $img1_size=$_FILES['img1_name']['size']; $img1_name=$_FILES['img1_name']['name']; $img1_type=$_FILES['img1_name']['type']; $img1=$_FILES['img1_name']['tmp_name']; $img1_error=$_FILES['img1_name']['error']; Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1019936 Share on other sites More sharing options...
inversesoft123 Posted March 1, 2010 Share Posted March 1, 2010 why this ? $ext=strtolower(substr($img1_name, strlen($img1_name)-4)); $whitelist = array(".jpg"); foreach ($whitelist as $ending) { if(substr($filename, -(strlen($ending))) != $ending) { echo "error msg"; } Even to make it more secure read first fev characters of file and check valid jpg image file $f = @fopen($_FILES['file']['tmp_name'],'r'); $s = @fread($f,4); @fclose($f); if($s != "ÿØÿà"){ Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1019939 Share on other sites More sharing options...
jakebur01 Posted March 1, 2010 Author Share Posted March 1, 2010 Now it is not resizing the original image. I have $max_image_width=400; $max_image_height=300; set in the config file. Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1019952 Share on other sites More sharing options...
jakebur01 Posted March 1, 2010 Author Share Posted March 1, 2010 Does anyone have any ideas on what might be causing this? Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1019984 Share on other sites More sharing options...
inversesoft123 Posted March 1, 2010 Share Posted March 1, 2010 why to go in such complicated manner if you have alternative easy solution for that For JPG $thumbWidth ="128"; // load image and get image size $img = imagecreatefromjpeg( "{$pathToImages}{$filename}" ); $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 imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); // save thumbnail into a file imagejpeg( $tmp_img, "{$pathToThumbs}{$filename}" ); For GIF and even with animated gif $thumbWidth ="128"; $im = new Imagick("$pathToImages/$filename"); $height=$im->getImageHeight(); $width=$im->getImageWidth(); $new_width = $thumbWidth; $new_height = floor( $height * ( $thumbWidth / $width ) ); // Resize all frames foreach ($im as $frame) { $frame->thumbnailImage("$new_width", "$new_height"); // Set the virtual canvas to correct size I obeserved that somtimes it wont work in case of more than 5 frames of image $frame->setImagePage("$new_width", "$new_height", 0, 0); } $im->writeImages("128/$filename", true); Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1020000 Share on other sites More sharing options...
jakebur01 Posted March 1, 2010 Author Share Posted March 1, 2010 I have an error on the gif resizer: Fatal error: Class 'Imagick' not found Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1020116 Share on other sites More sharing options...
inversesoft123 Posted March 2, 2010 Share Posted March 2, 2010 I have an error on the gif resizer: Fatal error: Class 'Imagick' not found You have to install ImageMagic and Imagick extension on server. If you have root access then install ImageMagick if you are on centos try with rpmforge like yum -y install ImageMagick for Imagick extension # cd /usr/local/src # wget http://pecl.php.net/get/imagick-2.2.2.tgz # tar zxvf ./imagick-2.2.2.tgz # cd imagick-2.2.2 # phpize # ./configure # make # make test # make install If on shared hosting ask your hosting co. for extension. Quote Link to comment https://forums.phpfreaks.com/topic/193780-image-upload/#findComment-1020279 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.