Hello.
I'm trying to move an uploaded file. I have been error checking this for hours and can't seem to figure it out. I am getting this to return false even though I can echo out $tmp_name and $target. I have tried this dozens of ways according to every tutorial I could find, but no luck.
I have commented in the code where I think the problem is, but I can't figure out what I'm doing wrong. It's at the bottom. Any help is appreciated, (and yes, I know I'm a noobie and am probably doing very redundant things -- try not to laugh too hard...)
//...lots of stuff happening up here unrelated to uploading the image...
$filename = $_FILES["image"]["name"];
if ($filename!="")
{
$filename = str_replace('.', '.', $filename, $numofdots);
if ($numofdots>=2)
{
$_SESSION['err']="Image upload failed because it had more than one file type ending!";
header('location: edit_adult_info.php');
exit;
}
$filename = explode('.', $filename);
$filename[0] = html_entity_decode($filename[0]);
$filename[0] = str_replace($attackchars, '', $filename[0]);
$filename[0] = stripslashes($filename[0]);
$filename[0] = mysql_real_escape_string($filename[0]);
$filename[1] = html_entity_decode($filename[1]);
$filename[1] = str_replace($attackchars, '', $filename[1]);
$filename[1] = stripslashes($filename[1]);
$filename[1] = mysql_real_escape_string($filename[1]);
//now fine file type depending on $filename[1]
$fileend=strtolower($filename[1]); //put it in lower case...
if ($fileend=="jpg"){$imagetype=".jpg";}
if ($fileend=="jpeg"){$imagetype=".jpeg";}
if ($fileend=="png"){$imagetype=".png";}
if ($fileend=="gif"){$imagetype=".gif";}
if ($fileend=="bmp"){$imagetype=".bmp";}
if ($fileend!="jpg" && $fileend!="jpeg" && $fileend!="png" && $fileend!="gif" && $fileend!="bmp")
{
$_SESSION['err']="Image upload failed: Unknown File Type!";
$_SESSION['errrpt']="You tried to upload a \".$fileend\" file.";
$_SESSION['errsol']="We only support .jpg, .jpeg, .png, .gif, and .bmp images.";
header('edit_adult_allinfo.php');
exit;
}
$filenamearray = array($filename[0], $filename[1]);
$filename = implode('.', $filenamearray);
// THE ABOVE WORKS...the IE problem was pjpeg and x-png
$target = "estickerimages/$stickernumber"."$imagetype";
//This is our size condition
$filesize=$_FILES['image']['size'];
if ($filesize>500000)
{
$_SESSION['err']="Image upload failed: Image was larger than 500KB!";
$_SESSION['errrpt']="Your image size was $filesize";
$_SESSION['errsol']="Please reduce your file size to less than 500KB.";
header ('location:edit_adult_allinfo.php');
exit;
}
if ($filesize==0)
{
$_SESSION['err']="Image upload failed: Error during security checks.";
$_SESSION['errrpt']="For client security, the specific error can not be shown.";
$_SESSION['errsol']="Try reducing your file size to less than 500KB.";
header ('location:edit_adult_allinfo.php');
exit;
}
//If everything is ok we try to save it to the server
$tmp_name=$_FILES['image']['tmp_name'];
echo"tmp_name: $tmp_name <br>";
echo"target: $target <br>";
$ismoved=move_uploaded_file($tmp_name, $target);
if ($ismoved==false){echo"not moved!";}
exit;
//tmp_name and target are correct...This is the output...
//tmp_name: /tmp/phpIOIakJ
//target: estickerimages/X2U8ACT5H4.png
//not moved!
/*
//this is what should happen once I get move_uploaded_file to work...
$imgpath=$target;
mysql_query("UPDATE `maintable` SET `imgpath` = '$imgpath' WHERE `stickernumber` = '$stickernumber'")or die (mysql_error());
*/
header ('location:edit_adult_allinfo.php');
exit;
}