Jump to content

File Upload Script = Fail


samato

Recommended Posts

Hello everyone.  I'm posting because I'm having difficulty using a file upload script I wrote in PHP.  (Based on a tutorial naturally.)  May someone more skilled than I could take a look at it?

 

Form: (simple, no ajax or jquery involved. I'll add that later.)

<form enctype="multipart/form-data" action="upload.php" method="POST">
<table><tr><td>File</td><td><input name="uploaded" type="file" /></td></tr>
<tr><td colspan="2"><input type="submit" value="Upload" style="float:right;" /></td></tr></table>
</form> 

 

Upload Script:

<?
session_start();
include('include/session.php');

/*IMAGE*/
$target = "upload/"; 
$target = $target . basename($_FILES['uploaded']['name']);
$name =  basename( $_FILES['uploaded']['name']);
$ok=1; 

global $database;


//This is our size condition 
if ($uploaded_size > 350000000) 
{ 
echo "Your file is too large.<br>"; 
$ok=0; 
} 

//This is our limit file type condition 
if ($uploaded_type =="text/php") 
{ 
echo "No PHP files<br>"; 
$ok=0; 
}

//Here we check that $ok was not set to 0 by an error 
if ($ok==0) 
{ 
Echo "Sorry your file was not uploaded"; 
} 

//If everything is ok we try to upload it 
else 
{ 
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{ 
$channel_number = $_SESSION['channel_number'];
$n = "INSERT INTO `documents` (`name`,`channel_number`) VALUES ('$name','$channel_number')";
mysql_query($n);
header("Location:index.php"); 
} 
else 
{ 
echo "Sorry, there was a problem uploading your file."; 
} 
} 
?>

 

The mysql query works fine, and it's just so that I can keep track of the uploads.  I'm well aware this is not a secure script, btw. I'm just doing it to learn.

Link to comment
https://forums.phpfreaks.com/topic/236179-file-upload-script-fail/
Share on other sites

Thanks. Ill check that now.  The problem is that it claims it has been uploaded, but no file appears in the directory.

 

EDIT: Full permissions are already set.  Doesn't seem to be that.  Furthermore, is there a way to restrict access to the folder via URL, but allow the php app to access it?  Perhaps another session variable?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.