uploading files
Posted: Fri Jun 06, 2008 8:27 am
hello,
i am making a simple cms which allows admin users to upload images to their database. i have used this particular file before but upon trying to implement it earlier i am getting the following error:
File Upload Failed, Debug Info: Array ( )
the code (which is quite weighty) is as follows:
<?php
if(isset($_POST['submit'])){
if(is_uploaded_file($_FILES['logo']['tmp_name'])){
if ($_FILES['logo']['type'] == "image/gif" ||
$_FILES['logo']['type'] == "image/jpeg" ||
$_FILES['logo']['type'] == "image/pjpeg"){
if ($_FILES['logo']['size'] < 1024 * 100){
list($width, $height, $type, $attr) = getimagesize($_FILES['logo']['tmp_name']);
if ($width < 200 || $height < 200){
//once all checks have been passed we make a directory using the followig format YYYYMMDD
//THE RELATIVE PATH WE USE FOR THIS SCRIPT
$dir_name = "../assets/images/portfolio_main/" . date("jmY");
//THE ABS PATH WE ALSO STORE FOR USING IN THE DB AND IMG TAGS
$img_path = "http://highway81design.com/10ant/assets ... folio_main" . date("jmY");
//we have to check if the directory already exists otherwise the script will error if it does
if(!is_dir($dir_name)){
mkdir($dir_name) or die("could not create directory " . $dir_name);
}
//so now we have the directory created, we must check for the file of the same name inside, and if it exists, we must add a number to our filename
//so we set an increment counter, and remember the original name of the file (otherwise we get 3_2_1_filename.jpg)
$i = 1;
$orig_filename = $_FILES['logo']['name'];
//check for the file in a loop
while(file_exists($dir_name . "/" . $_FILES['logo']['name'])){
//chnage the actual name of the file
//(here we add a number to the beginning, ideally we would break the filename apart and add the number at the end before the .extension, but i am trying to keep things simple here ...for now smile.gif
$_FILES['logo']['name'] = $i . "_" . $orig_filename;
//increment the counter just in case we have to come back through the loop again.
$i++;
}
//bingo, when the file no longer exists, we move the file, and give it the new name
move_uploaded_file($_FILES['logo']['tmp_name'], $dir_name . "/" . $_FILES['logo']['name']);
//$feedback = "File upload successful. The file has been saved as: " . $img_path . "/" . $_FILES['product_image']['name'];
$image_loc = $img_path . "/" . $_FILES['logo']['name'];
}else{
$image_feedback = "LOGO IMAGE SIZE ERROR: You have exceeded the maximum logo image dimensions of 200 x 200.";
}
}else{
$image_feedback = "FILESIZE ERROR: You have exceeded the maximum logo image file size of 100kb.";
}
}else{
$image_feedback = "FILETYPE ERROR: Wrong file type.";
}
}else{
echo "File Upload Failed, Debug Info: <br/>";
print_r($_FILES);
}
}
echo $image_feedback;
?>
any help would be greatly appreciated
thanks
i am making a simple cms which allows admin users to upload images to their database. i have used this particular file before but upon trying to implement it earlier i am getting the following error:
File Upload Failed, Debug Info: Array ( )
the code (which is quite weighty) is as follows:
<?php
if(isset($_POST['submit'])){
if(is_uploaded_file($_FILES['logo']['tmp_name'])){
if ($_FILES['logo']['type'] == "image/gif" ||
$_FILES['logo']['type'] == "image/jpeg" ||
$_FILES['logo']['type'] == "image/pjpeg"){
if ($_FILES['logo']['size'] < 1024 * 100){
list($width, $height, $type, $attr) = getimagesize($_FILES['logo']['tmp_name']);
if ($width < 200 || $height < 200){
//once all checks have been passed we make a directory using the followig format YYYYMMDD
//THE RELATIVE PATH WE USE FOR THIS SCRIPT
$dir_name = "../assets/images/portfolio_main/" . date("jmY");
//THE ABS PATH WE ALSO STORE FOR USING IN THE DB AND IMG TAGS
$img_path = "http://highway81design.com/10ant/assets ... folio_main" . date("jmY");
//we have to check if the directory already exists otherwise the script will error if it does
if(!is_dir($dir_name)){
mkdir($dir_name) or die("could not create directory " . $dir_name);
}
//so now we have the directory created, we must check for the file of the same name inside, and if it exists, we must add a number to our filename
//so we set an increment counter, and remember the original name of the file (otherwise we get 3_2_1_filename.jpg)
$i = 1;
$orig_filename = $_FILES['logo']['name'];
//check for the file in a loop
while(file_exists($dir_name . "/" . $_FILES['logo']['name'])){
//chnage the actual name of the file
//(here we add a number to the beginning, ideally we would break the filename apart and add the number at the end before the .extension, but i am trying to keep things simple here ...for now smile.gif
$_FILES['logo']['name'] = $i . "_" . $orig_filename;
//increment the counter just in case we have to come back through the loop again.
$i++;
}
//bingo, when the file no longer exists, we move the file, and give it the new name
move_uploaded_file($_FILES['logo']['tmp_name'], $dir_name . "/" . $_FILES['logo']['name']);
//$feedback = "File upload successful. The file has been saved as: " . $img_path . "/" . $_FILES['product_image']['name'];
$image_loc = $img_path . "/" . $_FILES['logo']['name'];
}else{
$image_feedback = "LOGO IMAGE SIZE ERROR: You have exceeded the maximum logo image dimensions of 200 x 200.";
}
}else{
$image_feedback = "FILESIZE ERROR: You have exceeded the maximum logo image file size of 100kb.";
}
}else{
$image_feedback = "FILETYPE ERROR: Wrong file type.";
}
}else{
echo "File Upload Failed, Debug Info: <br/>";
print_r($_FILES);
}
}
echo $image_feedback;
?>
any help would be greatly appreciated
thanks