-
Upload Problem
Hi all,
I'm using the following code to upload an image .....it works fine locally...But on the remote server it doesn't upload the image..
-------------------------------------------------------------------------------
//form field name is "images"
$image = "$images_name";
$exten = explode(".", $image);
$exten = strtolower($exten[1]);
$exten = chop($exten);
if (($exten == "gif") || ($exten == "jpg") || ($exten == "jpeg"))
{
$path = "whats_new/$image";
move_uploaded_file($images, "$path");
$sql = "INSERT INTO item (itm_name, description, unit_price, stock, image) VALUES ('$itm_name', '$description', '$unit_price', '$stock', '$image')";
$res = mysql_query($sql);
header("location:add_itm.php?msg=add");
}
else
{
echo "Wrong extension";
}
-----------------------------------------------------------------------------
Kindly check whats wrong..
Thanks
-
It would help to know what, if any, error your receive. If you don't receive an error, can you explain what happens?
-
Thank you for replying,
When i submit....The name of the file goes to the database but not the image on the remote server.....
It seems to me that there is something wrong in the path.
What exactly should the path be....i'm using
$path = "whats_new/$image";
Thanks
-
Try using the absolute path to your folder:
Code:
$path = "/home/your_site/public_html/whats_new/$image";
-
You also might want to try this:
Code:
$res = move_uploaded_file($images, "$path");
if ($res === false) {
die("Invalid upload file!");
}
That way you can make sure the upload file is valid. Also, where are you getting $images from?
Is that a global form variable? If so, that's a big no-no.
Try using:
Code:
$res = move_uploaded_file($_FILES['images']['name'], "$path");
if ($res === false) {
die("Invalid upload file!");
}
Assuming $images was a form variable.