loserWILL
07-06-2008, 05:55 PM
Hey, I have the following code and it doesn't seem to upload the file. I keep getting an error: "Error with uploading the image".
<?php
$path = "upload/";
$maxSize = "100000";
$maxWidth = "1500";
$maxHeight = "1500";
$allowedExt = ".gif,.bmp,.png,.jpg,.zip,.psd";
function get_ext($file){
$ex = strstr($file,".");
return $ex;
}
if (!$_POST['submit']){
?>
<form method="post" action="" enctype="multipart/form-data">
<label>Select Image</label><br />
<input name="image_file" type="file"><br />
<input name="submit" type="submit" value="Upload">
</form>
<?php
}
else{
$file = $_FILES['image_file'];
if($file == NULL){
echo "No image selected.";
}else{
$random = rand(0,9999);
$random *= rand(0,9999);
$random *= rand(0,9999);
$random /= 3;
$file_name = $random."-".basename($_FILES['image_file']['name']);
$up_path = $path.$file_name;
$ext = get_ext($file);
list($width, $height, $ftype, $attr) = getimagesize($_FILES['image_file']['tmp_name']);
$fileExt = explode(",",$allowedExt);
if ($width > $maxWidth){
echo "The width of the image can only be: ".$maxWidth."px";
}elseif ($height > $maxHeight){
echo "The height of the image can only be: ".$maxHeight."px";
}elseif (!in_array($ext,$fileExt)){
echo "File extention not recognized.<br /> Allowed extentions: ".$allowedExt;
}else{
if(move_uploaded_file($file_name,$up_path)){
}else{
echo "Error with uploading the image.";
}
}
}
}
?></span> </span>
<?php
$path = "upload/";
$maxSize = "100000";
$maxWidth = "1500";
$maxHeight = "1500";
$allowedExt = ".gif,.bmp,.png,.jpg,.zip,.psd";
function get_ext($file){
$ex = strstr($file,".");
return $ex;
}
if (!$_POST['submit']){
?>
<form method="post" action="" enctype="multipart/form-data">
<label>Select Image</label><br />
<input name="image_file" type="file"><br />
<input name="submit" type="submit" value="Upload">
</form>
<?php
}
else{
$file = $_FILES['image_file'];
if($file == NULL){
echo "No image selected.";
}else{
$random = rand(0,9999);
$random *= rand(0,9999);
$random *= rand(0,9999);
$random /= 3;
$file_name = $random."-".basename($_FILES['image_file']['name']);
$up_path = $path.$file_name;
$ext = get_ext($file);
list($width, $height, $ftype, $attr) = getimagesize($_FILES['image_file']['tmp_name']);
$fileExt = explode(",",$allowedExt);
if ($width > $maxWidth){
echo "The width of the image can only be: ".$maxWidth."px";
}elseif ($height > $maxHeight){
echo "The height of the image can only be: ".$maxHeight."px";
}elseif (!in_array($ext,$fileExt)){
echo "File extention not recognized.<br /> Allowed extentions: ".$allowedExt;
}else{
if(move_uploaded_file($file_name,$up_path)){
}else{
echo "Error with uploading the image.";
}
}
}
}
?></span> </span>