Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

need help with image upload problem

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

need help with image upload problem

Postby pugs421 » Sat Jun 28, 2003 9:14 pm

*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.
pugs421
New php-forum User
New php-forum User
 
Posts: 31
Joined: Sat Jun 28, 2003 9:09 pm

Postby pootergeist » Sun Jun 29, 2003 2:36 am

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.
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK

Postby pugs421 » Sun Jun 29, 2003 4:03 am

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.
pugs421
New php-forum User
New php-forum User
 
Posts: 31
Joined: Sat Jun 28, 2003 9:09 pm

Postby pootergeist » Sun Jun 29, 2003 6:10 am

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)
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron