Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Almost got it! Upload picture help please

Status
Not open for further replies.

pugs421

Technical User
Joined
Nov 25, 2002
Messages
114
Location
US
*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' 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(&quot;No file was selected!&quot;);
}
elseif($FileToUpload_size > $MaxFileSize) {
print(&quot;The file to upload is too big&quot;);
}
else {
$global_db = mysql_connect('localhost', 'newbie_update', 'boot');
mysql_select_db('newbie_update', $global_db) or die(&quot;Connection error&quot;);
$query = &quot;INSERT INTO setup (photo) VALUES ('$newfile$type')&quot;;
$result = mysql_query($query) or die(&quot;ERROR&quot;);
move_uploaded_file($FileToUpload, &quot;/home/newbie/public_html/images/$newfile$type&quot;);
}
?>
</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=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>

</form>
</body>

Any insight would be appreciated.
 
instead of giving a download try calling the gif in a html page.... (stupid qs but...)

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top