lienny
asked on
file upload and save path to mysql
hi,
Can someone help me with this?
I have a file upload script and it doesn't seem to be working correctly.
this is for a recipes database.
it's saving the name of the file, like shrimpmango.gif in the table, but isn't it suppose to save the path?
anyways, it's not saving the actual image to my uploads directory either. here's my script:
if(isset($bgid))
{
$folder = "/recipes/uploads/";
@copy("$image" , "$folder/$image_name");
$msg="lo";
$sql="insert into recipe(instructions,ingred ients,cont ributor,ca tegoryid,t itle,uplda te,descrip tion,prep, servings,i mage) values('$instructions','$i ngredients ','$contri butor',$bg id,'$title ',now(),'$ descriptio n','$prep' ,'$serving s','$image _name')";
$res=mysql_query($sql);
}
<form method="post" name="myform" action="<? print $PHP_SELF; ?>" onsubmit="javascript: return checkifvalid();" enctype="multipart/form-da ta">
<tr>
<td>Browse a File to Upload:</td>
<td><input type="file" name="image" size=45></td>
</tr>
<tr>
<td colspan="2" height="17"> <p align="center">
<input type="submit" name="Submit" value="Add Recipe">
</td>
</tr>
</form>
Can someone help me with this?
I have a file upload script and it doesn't seem to be working correctly.
this is for a recipes database.
it's saving the name of the file, like shrimpmango.gif in the table, but isn't it suppose to save the path?
anyways, it's not saving the actual image to my uploads directory either. here's my script:
if(isset($bgid))
{
$folder = "/recipes/uploads/";
@copy("$image" , "$folder/$image_name");
$msg="lo";
$sql="insert into recipe(instructions,ingred
$res=mysql_query($sql);
}
<form method="post" name="myform" action="<? print $PHP_SELF; ?>" onsubmit="javascript: return checkifvalid();" enctype="multipart/form-da
<tr>
<td>Browse a File to Upload:</td>
<td><input type="file" name="image" size=45></td>
</tr>
<tr>
<td colspan="2" height="17"> <p align="center">
<input type="submit" name="Submit" value="Add Recipe">
</td>
</tr>
</form>
ASKER
that still doesn't resolve the path name being stored in the db. also, it doesn't save my file to the uploads directory.
Ok, let's start from the top
use this:
# path to save the file to
$folder = "/recipes/uploads";
# get the temporary name of the file
$image = $_FILES['image']['tmp_name
# copy the temp file to the file directory
@copy($image, "$folder/$image");
Once we get this working, we'll worry about adding the file path to the database. Let me know how this turns out.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
okay...so it's saving the path correctly in mysql, but it's still not saving the file into the directory.
how did it suddenly start saving the path?
are you getting any errors when trying to copy?
do you have proper permissions set for the uploads directory?
have you made the changes described above?
are you getting any errors when trying to copy?
do you have proper permissions set for the uploads directory?
have you made the changes described above?
ASKER
made change like you suggested above...then i put the $folder/$orig_filename into my insert statement...now when i submit the page it inserts the path.
no errors at all.
set the permissions to 777
no errors at all.
set the permissions to 777
Reading the upload manual on php.net shows also that you never should use copy when handling uploaded files. cLFlaVA should be aware of the existence of move_uploaded_file() function.
This will not totaly solve your problem though, but could prevent problems when running on commercial server from webhosting parties.
Regards
-r-
This will not totaly solve your problem though, but could prevent problems when running on commercial server from webhosting parties.
Regards
-r-
"$folder/$image_name" according to your code above, yet you're only inserting $image_name into the database.