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
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?

Link to comment
Share on other sites

Using the FTP i checked and there are no files uploading.  For some reason the page redirects me to my index page even tho the download doesn't complete. Odd.  It also kills one of my session variables.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.