File Upload

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Hasna
Forum Newbie
Posts: 1
Joined: Mon Feb 02, 2009 12:08 am

File Upload

Post by Hasna »

Hi there, whenever I try to upload a file I get an error message Error Uploading File. Please advice


<?
//include("connection.php");
$connection=mysql_connect($hostname,$user,$pass)
or die ("Unable to connect to the database");
$query4= "Select max(applicant_id) as cvid from moh_job_app";
$result4=mysql_db_query($database,$query4,$connection)
or die("Error in query:$query4.". mysql_error());

if(mysql_num_rows($result4)==0)
{
mysql_close($connection);
}
else
{
list($maxcvid) = mysql_fetch_row($result4);

$imtemp=$_FILES['file1']['tmp_name'];
if(isset($_POST['submit']) && ($_FILES["file1"]["size"] > 0)) {

$imtemp=$_FILES['file1']['tmp_name'];
$uploadfile=$_FILES['file1']['name'];

$fname= $maxcvid . $uploadfile;
$uploaddir = "upload/";
$newfile = $uploaddir . $fname;

if(copy($imtemp, $newfile)) {
print("<h5><center> UPLOAD SUCCESSFUL!</h5></center>");

$connection=mysql_connect($hostname,$user,$pass)
or die ("Unable to connect to the database");
// sql= "Select cvname from mohjob where applicant_id = (SELECT max(applicant_id) from mohjob)" ;
/* $query= "update mohjob
set cvname='$fname'
where applicant_id = (SELECT max(applicant_id) from mohjob)"; */

// $vmaxcvid=$_POST['maxcvid'];

$query= "update moh_job_app
set cvname='$fname'
where applicant_id = '$maxcvid'";
echo"<center>Click <a href ='moh_experience.php?email={$_SESSION['SESSION_UID']}'>here</a> to go to Experience Page</center>";
echo"<body bgcolor=#FCFBE9>";
// header("LOCATION:moh_experience.php");
$result=mysql_db_query($database,$query,$connection)
or die("Error in query:$query.". mysql_error());
mysql_close($connection);

} else {
print("<h3><center>ERROR UPLOADING FILE!</h3></center>");
echo"<body bgcolor=#FCFBE9>";
}} else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" [ccc] enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value=" 2097152">
<align=left><u>Attach CV</u> <br>
<br>File:<input type="file" name="file1">

<br><input type="submit" name="submit" value="UPLOAD"><br>
<br><font size=2><B> If you do not attach your CV, your application will not be considered.</b>
</form>
<?
}
}
?>
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: File Upload

Post by susrisha »

noticed two things which might be useful:

1. You have specified the max size in the form but not checked if the uploaded file exceeds the max size.

Code: Select all

 
<input type="hidden" name="MAX_FILE_SIZE" value="2097152">
 
2. Try using move_uploaded_file function instead of using copy.
check the usage http://in.php.net/manual/en/function.mo ... d-file.php

3. Try checking if the file is uploaded or not using is_uploaded_file function


My guesses for the error:
1. No write permissions for the upload folder to which you are uploading the files
2. Maximum upload file size limited in php to 2MB. That will be present in php.ini file
3. Also check the limit for post data in php.ini file.

Code: Select all

 
post_max_size
 
Let me know if that works
Post Reply