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>";
}
}