smphil
asked on
Upload status script
How can I write a upload status script for my picture upload script. here is the upload script. If the upload script can be put on a seperate page that would be better and just require() it with this upload script.
<?php
$myback = "model-picture-form.php";
$limitedext = array("image/gif","image/j pg","image /jpeg","im age/pjpeg" , "image/bmp");
$uploaddir = 'pictures/';
$count = isset( $_POST["count"] ) ? intval( $_POST["count"] ) : 1;
for( $i = 1; $i <= $count; $i++ )
{
if( isset($_FILES['img'.$i]) && !empty($_FILES['img'.$i][' tmp_name'] ) )
{
$tmp_filename = $_FILES['img'.$i]['tmp_nam e'];
$filename = basename($_FILES['img'.$i] ['name']);
$filetype = $_FILES['img'.$i]['type'];
$filesize = $_FILES['img'.$i]['size'];
$uploadfile = $uploaddir . $filename;
$fileext = strrchr($filename, '.');
// Return error if the file-size is greater than 30000 bytes.
if( $filesize > 30000 )
{
echo "<br><br>Sorry, File size is bigger than 30 KB and has not uploaded.<p> Please go back an find a picture with a smaller file size. <a href='$myback'>Back To Form</a>";
}
else
{
if( in_array(strtolower($filet ype), $limitedext) )
{
if ( $handle = opendir($uploaddir) )
{
while ( false !== ( $file = readdir($handle) ) )
{
if ( $file != "." && $file != ".." )
{
if( strtolower($file) == strtolower($filename) )
{
$changed_file_name = basename( $filename, $fileext ) . '_' . date("YmdHis") . $fileext;
$uploadfile = $uploaddir . $changed_file_name;
}
}
}
closedir( $handle );
}
if ( move_uploaded_file($tmp_fi lename, $uploadfile) )
{
chmod( $uploadfile, 0755 );
print ". <br><br>File is valid, and was successfully uploaded. <a href='$uploadfile' target=\"_blank\">Click here</a> to view the file";
}
else
{
print "<br><br>Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES);
}
}
else
{
echo ". <br><br>Invalid file and not uploaded. Please upload only JPG or GIF or BMP file.";
}
}
}
}
?>
<?php
$myback = "model-picture-form.php";
$limitedext = array("image/gif","image/j
$uploaddir = 'pictures/';
$count = isset( $_POST["count"] ) ? intval( $_POST["count"] ) : 1;
for( $i = 1; $i <= $count; $i++ )
{
if( isset($_FILES['img'.$i]) && !empty($_FILES['img'.$i]['
{
$tmp_filename = $_FILES['img'.$i]['tmp_nam
$filename = basename($_FILES['img'.$i]
$filetype = $_FILES['img'.$i]['type'];
$filesize = $_FILES['img'.$i]['size'];
$uploadfile = $uploaddir . $filename;
$fileext = strrchr($filename, '.');
// Return error if the file-size is greater than 30000 bytes.
if( $filesize > 30000 )
{
echo "<br><br>Sorry, File size is bigger than 30 KB and has not uploaded.<p> Please go back an find a picture with a smaller file size. <a href='$myback'>Back To Form</a>";
}
else
{
if( in_array(strtolower($filet
{
if ( $handle = opendir($uploaddir) )
{
while ( false !== ( $file = readdir($handle) ) )
{
if ( $file != "." && $file != ".." )
{
if( strtolower($file) == strtolower($filename) )
{
$changed_file_name = basename( $filename, $fileext ) . '_' . date("YmdHis") . $fileext;
$uploadfile = $uploaddir . $changed_file_name;
}
}
}
closedir( $handle );
}
if ( move_uploaded_file($tmp_fi
{
chmod( $uploadfile, 0755 );
print ". <br><br>File is valid, and was successfully uploaded. <a href='$uploadfile' target=\"_blank\">Click here</a> to view the file";
}
else
{
print "<br><br>Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES);
}
}
else
{
echo ". <br><br>Invalid file and not uploaded. Please upload only JPG or GIF or BMP file.";
}
}
}
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.