Image Upload in PHP
Hi Everyone,
I have a script here that will allow my user to upload an image to there server space. I have had it working a very very long time ago and when i tryed to us this script again I keep getting this error, my problem is not sure what the error means and how to solve the problem can anyone help me.
This is a copy of the first script with the small form:
<?php
<html>
<head>
<title>User Image Upload</title>
</head>
<body>
<table border=\"0\">
<form action=\"uploadimage.php\" method=\"post\" enctype=\"multipart/form-data\" name=\"imageupload\">
<input type=\"hidden\" name=\"id\" value=\" echo $id; \">
<tr>
<td colspan=\"2\"> echo \"$row[psname]\"; </td>
</tr>
<tr>
<td>New Image file </td>
<td><input name=\"imgfile\" type=\"file\" ></td>
</tr>
<tr>
<td colspan=\"2\"><div align=\"center\">
<input type=\"submit\" name=\"submit\" value=\"Upload\">
</div></td>
</tr>
</form>
</table>
echo\"<a href=adminlist.php>Go back to the main menu</a>\";
</body>
</html>
?>
Here is uploadimage.php
<?php
PHP
echo $imgfile_name;
$dir=\"../psimages/\";
$ifile = $dir . $imgfile_name;
$ext = strrchr($imgfile_name,'.');
if (isset($submit))
{
$fileexists = \"n\";
while ($fileexists != \"y\")
{
copy($imgfile,$dir.$imgfile_name);
$fileexists = \"y\";
}
if (!is_uploaded_file ($imgfile))
{
echo \"<b>$imgfile_name</b> couldn't be copied !!\";
}
}
echo \"<img src=../psimages/$imgfile_name>\";
echo\"<a href=adminlist.php>Go back to the main menu</a>\";
?>
and this is the error i'm getting:
06.jpg
Warning: copy(../psimages/06.jpg): failed to open stream: Permission denied in /home/username/public_html/foldername/admin/uploadimage.php on line 16
Go back to the main menu
Can anyone help me please
Busy posted this at 10:21 — 1st November 2004.
He has: 6,151 posts
Joined: May 2001
Have you chmod'd the upload folder to 777 ?
You may also have to use the complete path to the place you want to put it
$dir1 = "/home/username/public_html/foldername/admin/";
$dir = "psimages/";
copy(file,dir1.dir.file) of course these would be the variables used.
for security you should really use
is_uploaded_file($_FILES['imgfile']['tmp_name']
if done like:
if(is_uploaded_file($_FILES['imgfile']['tmp_name']) { ... }
reads: if was uploaded from your form, return true, otherwise return false (security risk)
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.