need help with image upload problem

A

Anonymous

Guest
*Disclaimer* I'm a newbie

After trying many different scipts to upload files I finally got one to work...almost.

The script renames the file to something like this 'phpcCsWrf.jpg' and stores it in the directory you choose and stores the filename in the database. I set up the permissions to 777 in the image directory and the image gets uploaded to it with no problem. The problem occurs when I try to access the newly uploaded picture. I get an access denied when trying to download the picture to my local or even trying to view it through my file manager. The newly uploaded pictures are the only files in the folder that yeild this error message. I hope that's enough info for someone to give me an idea of whats going on but if not here is the script i am using:

<body>
<?php
if ($FileToUpload_type == 'image/gif') {
$type = '.gif';
}
if ($FileToUpload_type == 'image/pjpeg') {
$type = '.jpg';
}
if ($FileToUpload_type == 'image/x-png') {
$type = '.jpg';
}
$newfile = substr($FileToUpload, -9);
if($FileToUpload_name = '') {
print("No file was selected!");
}
elseif($FileToUpload_size > $MaxFileSize) {
print("The file to upload is too big");
}
else {
$global_db = mysql_connect('localhost', 'newbie_update', 'boot');
mysql_select_db('newbie_update', $global_db) or die("Connection error");
$query = "INSERT INTO setup (photo) VALUES ('$newfile$type')";
$result = mysql_query($query) or die("ERROR");
move_uploaded_file($FileToUpload, "/home/newbie/public_html/images/$newfile$type");
}
?>
</body>
_____________________________________________________

@Html page for user upload@

<body>
<form name=form1 action=upload_file.php method=post enctype=multipart/form-data>

<input type=file name=FileToUpload>
<input type=hidden name=MaxFileSize value=64000>
<input type="submit" name="Submit" value="Submit">

</form>
</body>

Any insight would be appreciated.
 
try

chmod("/home/newbie/public_html/images/$newfile$type",0777);

on the line after move_uploaded_file.

subnote: at some stage you are going to have to rewrite all that code to account for super_globals - will need to start accessing the file variables through the $_FILES array.
 
IT WORKED!!! Thanks
______________________________

I knew I would have to customize the code in order to do what I wanted it to do, (ex. make filename the screenname of the person uploading it) but would you mind explaining what you mean by this "you are going to have to rewrite ALL that code to account for super_globals ". I'm new to this stuff. Thanks.
 
vague explaination

$FileToUpload_type <--- deprecated since php4.2 (with reg_globs off)
use $_FILES['FileToUpload']['type']

same with all the others.

var_dump($_FILES); would tell you all the variables that are accessible within the array - just substitute them for the deprecated globals that you are using (well, do that when the script stops working / admin upgrades php)
 
Back
Top