Jump to content

Upload problem driving me crazy


steve490

Recommended Posts

hello there,

 

Can any tell me why this upload code isn't working. What its suppose to do is upload a picture to a server and its id to a database with the users session data. its uploading to the database but not the the server folder heres the code:

 


$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = '******';
mysql_select_db($dbname);

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

$pic = ($_FILES['uploadedfile']['name']);

mysql_query ("INSERT INTO img (name, email) VALUES ('uploads/$pic','$_SESSION[email]')");  

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded to " . $target_path;
} else{
    echo "There was an error uploading the file, please try again!";
}



 

here's the html

 


<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />

 

cheers in advance

Link to comment
https://forums.phpfreaks.com/topic/190929-upload-problem-driving-me-crazy/
Share on other sites

Okay, it really does not seem to be a code problem to me. It might be a few other things. Try these and see if it helps:

 

1.) The folder "uploads" might need the permissions to be changed. Try setting them 0755 or 0777.

2.) if you can, depending on your privileges with your server, try putting the uploads directory outside of the web root. So instead of the variable $tagert_path = 'uploads/' it would be written like this: $target_path = '../uploads/'

3.) If you cannot change the path of the uploads directory, try add a forward slash in front of the directory like this: $target_path = '/uploads/'

 

Try those and hopefully one of those work for you.

We cannot tell you why the upload is failing because your code has no logic in it to test for any of the possible upload errors and tell you which one it causing the upload to fail. See this recent thread for the things you must test before you attempt to access any of the uploaded file information - http://www.phpfreaks.com/forums/index.php/topic,286370.msg1357855.html#msg1357855

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.