samato Posted May 12, 2011 Share Posted May 12, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236179-file-upload-script-fail/ Share on other sites More sharing options...
requinix Posted May 12, 2011 Share Posted May 12, 2011 So what are you having difficulty with? Quote Link to comment https://forums.phpfreaks.com/topic/236179-file-upload-script-fail/#findComment-1214317 Share on other sites More sharing options...
dougjohnson Posted May 12, 2011 Share Posted May 12, 2011 You might check the permissions on the directory you are uploading to and make sure your app can create files and folders at that location. Quote Link to comment https://forums.phpfreaks.com/topic/236179-file-upload-script-fail/#findComment-1214479 Share on other sites More sharing options...
samato Posted May 12, 2011 Author Share Posted May 12, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/236179-file-upload-script-fail/#findComment-1214544 Share on other sites More sharing options...
Sanjib Sinha Posted May 12, 2011 Share Posted May 12, 2011 It happens : message comes out like data, image uploaded successfully. But can you physically check the folder whether anything uploaded or not? If nothing happens then please use print_r() function to see what happens actually. Quote Link to comment https://forums.phpfreaks.com/topic/236179-file-upload-script-fail/#findComment-1214548 Share on other sites More sharing options...
samato Posted May 12, 2011 Author Share Posted May 12, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236179-file-upload-script-fail/#findComment-1214750 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.