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

Image upload problems

images php coding issues or problems here.

Moderators: macek, egami, gesf

Image upload problems

Postby dai » Fri Jun 27, 2003 2:16 pm

I am trying to upload images to mySQL using the following script:

$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);

The $img variables come from a form.

This works fine on my local machine however when uploaded to the server and test it i get:

Warning: fopen("C:\\Inetpub\\wwwroot\\websites\\llandrpcen\\img\\mainimg\\lotfdeng.gif", "r") - No such file or directory in /home/torpex/public_html/proj/llandrpcen/upimg.php on line 14

I know this is because the file is local on the testing server (my machine), how can i resolve this,
thanks for any help :?
dai
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Jun 27, 2003 2:08 pm

Postby Redcircle » Fri Jun 27, 2003 10:00 pm

Your remote server cannot read a file on your local machine. You need to upload the file to the server first.

see http://us4.php.net/features.file-upload for more info.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby dai » Fri Jun 27, 2003 11:58 pm

That is what i am trying to do with this script.

I have changed the upload form slightly on chaceking the link you supplied thankyou however I now get the following error:

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);
?>
**********************************************

Any help greatly appreciated.
dai
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Jun 27, 2003 2:08 pm

Postby pio » Wed Mar 10, 2004 10:36 am

I really dont think any of that is going to get you anywhere, man...

to upload an image to the server use this code (or something similar):
Code: Select all

if(upload==TRUE) {

$targetfolder = $_SERVER['DOCUMENT_ROOT']."/your/folder/here/";
$targetfile = $targetfolder . $_FILES['imgfile']['name'];
// the lines gives you this string:
// your/server/root/your/folder/here/imgfile.gif
// no need to specify image type

move_uploaded_file($_FILES['imgfile']['tmp_name'], $targetfile);

};



You can use the $_FILES['imgfile'] variable to get info about filesize etc.:

Code: Select all
$size = $_FILES['imgfile']['size'];


then you could do something like this:
Code: Select all
strSQL = "Update tblimage Set imgtype='$imgtype', imglink='$imglink',imgdata='$targetfile'
Where imgname='$imgname'";


just a suggestion. (*bangs head into desk realizing thread is 9 months old)
User avatar
pio
New php-forum User
New php-forum User
 
Posts: 12
Joined: Sat Nov 29, 2003 9:58 am
Location: Oslo, Norway


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 3 guests

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

cron