Search
Left Quote    By failing to prepare, you are preparing to fail.
- Benjamin Franklin    
Right Quote
 
[login] | [Register]
Forum Index » General Discussion » Viewing Topic and Replies
Post Reply


        Viewing Topic: Help With Image Upload Check
  This user is offline  jmessina001
  Subject: "Help With Image Upload Check" Posted: @ 3:37 am on Oct 25 2007   
Member #: 450
Rank: User - (2)
Since: 10/25/07
Posts: 2

Maybe someone can help me here. The script works to upload images to my mysql database and performs the required checks except for one. Anytime I upload a large file it fails and I receive "Internet Explorer Cannot Display The Webpage". Also have to mention that MAX_FILE_SIZE on the form is set to 690000, but any file over 224kiloBytes fails. My understanding is that 690000 equates to 690kiloBytes. At this point, I'd be happy with getting the error message that is supposed to display to work when the file is over the file size. I'm a beginner, so any help is greatly appreciated. Thanks in advance for your help.


Here is the script:


FORM SCRIPT:

<form method="po st" action="te stnewuploadfrmA .php" enctype="m ultipart/form-d ata">
<table width="350 " border="0& quot; cellpadding=&qu ot;1" cellspacing=&qu ot;1" class="box ">
<tr>
<tr>< td>Descripti on:</td>& lt;td><in put type="text " size=25 name="desc ription"&g t;</td>&l t;/tr>
<tr>< td><input type="hidd en" name="id&q uot; value="< ;? echo $picID ?>"/> ;</td>< ;/tr>
<tr>
<td>File Name:</td> ;
<td>< input type="hidd en" name="MAX_ FILE_SIZE" value="690 000">&l t;input size=25 name="user file" type="file " /></td> ;
<td width="80& quot;><in put name="uplo ad" type="subm it" class="box " value=" Upload"/&g t;</td>&l t;/tr>
</tr>
</table>
</form>


UPLOAD SCRIPT:


<?

//check if they decided to upload a pic:
if(isset($_POST ['upload']) && $_FILES['userfi le']['size'] > 0) {


//define maximum file size
$max_size = $_FILES['userfi le']['size'];
$max_frm_size = $_POST['MAX_FIL E_SIZE'];
$info = getimagesize($_ FILES['userfile ']['tmp_name']) ;

//This is where I am having issues with this script
//check file-size (in bytes):
if($_FILES['use rfile']['size'] < $max_frm_size) {


//Check if the file is JPEG image
$fileTest = basename($_FILE S['userfile'][' name']);
$ext = substr($fileTes t, strrpos($fileTe st, '.') + 1);
$imageTypes = array ('jpeg', 'jpg');

if ((in_array(strt olower($ext), $imageTypes))) {


//define variables for adding to database
$fileName = $_FILES['userfi le']['name'];
$tmpName = $_FILES['userfi le']['tmp_name' ];
$fileSize = $_FILES['userfi le']['size'];
$fileType = $_FILES['userfi le']['type'];
$ID = $_POST['id'];
$description = $_POST['descrip tion'];

$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpNa me));
$content = addslashes($con tent);
fclose($fp);

if(!get_magic_q uotes_gpc())
{
$fileName = addslashes($fil eName);
}


$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'pass';
$dbname = 'name';

// Connects to your Database
mysql_connect($ dbhost, $dbuser, $dbpass) or die(mysql_error ());
mysql_select_db ($dbname) or die(mysql_error ());


$result="U PDATE uploads SET description='$d escription', data='$content' , filename='$file Name', filesize='$file Size', fileType='$file Type' WHERE id='$ID' AND username='$user name'";

mysql_query($re sult) or die(mysql_error ());

mysql_close();


print "<p> File ID: <b>$ID< ;/b><br&g t;";
print "<p> File Name: <b>$fileN ame</b>&l t;br>";
print "<p> File Size: <b>$fileS ize</b>&l t;br>";
print "<p> File Type: <b>$fileT ype</b>&l t;p>";
print "To upload another file <a href=http://www .mywebsite.com/ index.htm> Click Here</a>& quot;;


} else { echo "You can only upload JPEG images!"; }

} else { echo "File is too large! file size is $max_size and max form size is $max_frm_size "; }

} else { echo "You must select a file to upload!"; }


?>


Edited at 04:10:19 am on 10/25/07


    Viewed: 7,257 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Help With Image Upload Check" Posted: @ 12:39 pm on Oct 25 2007    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

Please note that the script shown above is not the upload script from this site.

For some reason, I dont even in the code where the actual upload takes place. Where are you storing the images? Where is that shown in the code? Where did this code come from, did you create it?

You might try reading through the PHP Image Upload article on this site to see what the process is generally for uploading files.




-bs0d | AllSyntax.com

    Viewed: 7,238 Times | Reply to This | To top
  This user is offline  jmessina001
  Subject: "re: Help With Image Upload Check" Posted: @ 4:44 pm on Oct 25 2007    
Member #: 450
Rank: User - (2)
Since: 10/25/07
Posts: 2

  jmessina001 said...

< i> Maybe someone can help me here. The script works to upload images to my mysql database and performs the required checks except for one. Anytime I upload a large file it fails and I receive "Internet Explorer Cannot Display The Webpage". Also have to mention that MAX_FILE_SIZE on the form is set to 690000, but any file over 224kiloBytes fails. My understanding is that 690000 equates to 690kiloBytes. At this point, I'd be happy with getting the error message that is supposed to display to work when the file is over the file size. I'm a beginner, so any help is greatly appreciated. Thanks in advance for your help.


Here is the script:


FORM SCRIPT:

<form method="p ost" action="t estnewuploadfrm A.php" enctype=" multipart/form- data">
<table width="35 0" border="0 " cellpadding=&q uot;1" cellspacing=&q uot;1" class="bo x">
<tr>
<tr>< td>Descripti on:</td>& lt;td><in put type="tex t" size=25 name="des cription" ></td> </tr>
<tr>< td><input type="hid den" name="id " value="&l t;? echo $picID ?>"/&g t;</td>&l t;/tr>
<tr>
<td>File Name:</td> ;
<td>< input type="hid den" name="MAX _FILE_SIZE&quo t; value="69 0000"> <input size=25 name="use rfile" type="fil e" /></td> ;
<td width="80 ">< input name="upl oad" type="sub mit" class="bo x" value=" Upload"/& gt;</td>& lt;/tr>
</tr>
</table>
</form>


UPLOAD SCRIPT:


<?

//check if they decided to upload a pic:
if(isset($_POST ['upload']) && $_FILES['userf ile']['size' ] > 0) {


//define maximum file size
$max_size = $_FILES['userf ile']['size' ];
$max_frm_size = $_POST['MAX_FI LE_SIZE'];
$info = getimagesize($_ FILES['userfil e']['tmp_name ']);

//This is where I am having issues with this script
//check file-size (in bytes):
if($_FILES['us erfile']['siz e'] < $max_frm_size) {


//Check if the file is JPEG image
$fileTest = basename($_FILE S['userfile'] ['name']);
$ext = substr($fileTes t, strrpos($fileTe st, '.') + 1);
$imageTypes = array ('jpeg', 'jpg');

if ((in_array(strt olower($ext), $imageTypes))) {


//define variables for adding to database
$fileName = $_FILES['userf ile']['name' ];
$tmpName = $_FILES['userf ile']['tmp_na me'];
$fileSize = $_FILES['userf ile']['size' ];
$fileType = $_FILES['userf ile']['type' ];
$ID = $_POST['id'];
$description = $_POST['descri ption'];

$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpNa me));
$content = addslashes($con tent);
fclose($fp);

if(!get_magic_q uotes_gpc())
{
$fileName = addslashes($fil eName);
}


$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'pass';
$dbname = 'name';

// Connects to your Database
mysql_connect($ dbhost, $dbuser, $dbpass) or die(mysql_error ());
mysql_select_db ($dbname) or die(mysql_error ());


$result=" UPDATE uploads SET description='$ description', data='$content ', filename='$fil eName', filesize='$fil eSize', fileType='$fil eType' WHERE id='$ID' AND username='$use rname'";

mysql_query($re sult) or die(mysql_error ());

mysql_close();


print "<p> ;File ID: <b>$ID< ;/b><br&g t;";
print "<p> ;File Name: <b>$fileN ame</b>&l t;br>" ;
print "<p> ;File Size: <b>$fileS ize</b>&l t;br>" ;
print "<p> ;File Type: <b>$fileT ype</b>&l t;p>";
print "To upload another file <a href=http://www .mywebsite.com/ index.htm> Click Here</a> ";


} else { echo "You can only upload JPEG images!"; }

} else { echo "File is too large! file size is $max_size and max form size is $max_frm_size "; }

} else { echo "You must select a file to upload!"; }


?>


Thanks for taking the time to review this. The images are actually upload to an mysql database through another form. This particular script is actually the script that allows the user to update/replace their pics in the database.

The script works to upload/update the images in the database, but when I try uploading/updat ing a pic larger than 224kb it fails and the script does not show the error message that I have set. I'm just not sure what is happening when I try to upload files greater than 224kb but still under 1MB to update the image in the database. It works perfectly when I upload small files.




    Viewed: 7,232 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Help With Image Upload Check" Posted: @ 5:43 pm on Oct 25 2007    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

Thats crazy. Maybe post the code from the other part of the script. also, if you use the bbCode for code samples (code button above) then it will make your code easier to read and not clutter the forum thread.




-bs0d | AllSyntax.com

    Viewed: 7,228 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank