image upload problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
daimoore
Forum Newbie
Posts: 1
Joined: Sat Jun 28, 2003 10:55 am

image upload problems

Post by daimoore »

hi,
When trying to upload images to mysql as blob i get the following errors:

Warning: open_basedir restriction in effect. File is in wrong directory in /home/torpex/public_html/cgi-bin/upfile.php on line 2

Warning: fopen("/tmp/phpJ6i7eC", "r") - Operation not permitted in /home/torpex/public_html/cgi-bin/upfile.php on line 2

Any Ideas.

Upload Form:
******************************************
<form method="POST" action="upimg.php?upload=true" enctype="multipart/form-data">
<table align="center" class="formcss">
<tr>
<td>Type</td>
<td> <select name="imgtype">
<option value="image/gif">GIF</option>
<option value="image/jpeg">JPEG</option>
</select> </td>
</tr>
<tr>
<td>File</td>
<td><input type="file" name="imgfile"></td>
</tr>
<tr>
<td> Link
<div align="center"> </div></td>
<td><input type="text" name="imglink" value="<?php echo $strLink ?>"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="hidden" name="imgname" value="<?php echo $strName ?>">
<input type="submit" name="submit" value="Upload">
</div></td>
</tr>
</table>
</form>
**********************************************

include script (in cgi-bin)
**********************************************
<?php
$hndl=fopen("$imgfile","r");
$imgdata=fread($hndl,filesize("$imgfile"));
$imgdata=addslashes($imgdata);
$strSQL = "Update tblimage Set imgtype='$imgtype', imglink='$imglink',imgdata='$imgdata'
Where imgname='$imgname'";
mysql_query($strSQL)
or die("Could not execute query");
fclose($hndl);
?>
**********************************************
I know this is because the file is going into the tmp file which is above my home directory, is there any way using php i can retrieve the file from my hosts temp dir or even redirect it before it gets there.

Any help greatly appreciated.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Is this on a hosted site or your own PC or server?

Mac
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Use the

Code: Select all

[/b] & [b]
[/b] tags to show source, it helps when examining the code.
Post Reply