0

ok i have a problem and it does not seem to be the php.ini problem.

what would cause my upload script for files to not completely execute and then just show me a blank page. not file uploaded and no record to the DB.

i am giving the upload code to see if there is a problem in it.

$id = $_GET['id'];
$file = $_FILES['document']['name'];
$docname = $_POST['docname'];

if ($file == '') {
	echo 'Please select a document to upload.';
	echo '<br /><a href="javascript:history.go(-1);">&lt;&lt Go Back</a>';
	exit;
}
if ($docname == '') {
	echo 'Please insert a document name so that you know what it is.';
	echo '<br /><a href="javascript:history.go(-1);">&lt;&lt Go Back</a>';
	exit;
}


			  $filename = $file;
			  $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
			  $ext = substr(strrchr($filename, "."), 1);
			  
			  $allowedExtensions = array("doc","xls","ppt","pdf"); 
			  if (!in_array($ext, $allowedExtensions)) {
				  echo "File type not allowed";
				  echo '<br /><a href="javascript:history.go(-1);">&lt;&lt Go Back</a>';
				  exit;
				  }
			  
			  $randName = md5(rand() * time());
			  $filename = $randName . '.' . $ext;;
			  $source = $_FILES['document']['tmp_name'];
			  $target = "documents/".$filename;

					$add = "documents/$filename";
                       //echo $_FILES['images']['type'][$key];
			     // echo "<br>";
					copy($_FILES['document']['tmp_name'], $add);
					chmod("$add",0777);
						
			$query = "INSERT INTO paperwork (file, name, company_id, file_id)
											   VALUES ('$filename', '$docname', '$company_id', '$id')";

			$result = mysql_query($query);			
			if ($result) {
	$message = 'Yay the query was successfully run555.';
}
else{
	$message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: <em>' . $query . '</em>';
    die($message);
}



echo '<h3>The File Was Uploaded Successfully</h3>';
echo '<code><script language=javascript>setTimeout(\'parent.tb_remove(); parent.location.reload(1)\', 1500);</script></code>';

thanks in advanced

3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by itisnot_me
0

Are you trying to upload files bigger than the size limit in php.ini? if the script works with small size file then the script is fine and the error is in php.ini.

Another issue may be that your server has some strict security. Sometimes mod_security doesn't like a part of the url. If you have mod_security check the logs.

If indeed you are uploading big files but your settings are ok with this check that the script is not timing out. Use set_time_limit(0); at the beginning of the script.

0

thanks for the reply. i dont understand what the problem is. i did upload a smaller file. and i did add that set_time thing and still have that issue. i am soo stumped. and it is getting annoying

0
case "paperwork":
        echo '
		<div style="border:dashed 1px #000000;">
		  <form action="add.php?id='.$id.'" method="post" enctype="multipart/form-data" >
  <div class="blue" style="text-align:left">
  <input name="addpaperwork" type="submit" value="Add&nbsp;Paperwork" class="btn" />
  or <a href="#" onclick="parent.tb_remove();">cancel</a><br />
 </div> 
 <table cellpadding="5">
  <tr>
    <td>Document:</td>
    <td><input type="file" name="document"/></td>
  </tr>
  <tr>
    <td>Document Name:</td>
    <td><input name="docname" type="text" /></td>
  </tr>
</table>
  </form>
  </div><br /> 
		';
0

i have reuploaded a new php.ini and changed just the memory limit and the max file size. and i still get a blank page in the middle of the upload. it is really weird cause it used to work but i dont know why it just started to act up.

i even added a couple of echos to it and i didnt even get those

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.