Hi guys,
I am wirting a script to upload an image file, but I get the error:
copy() [function.copy]: Filename cannot be empty in
Obviouly it has something to do with the copy() function - (copy($HTTP_POST_FILES['product_img']['tmp_name'], $path))
I think it is not copying from my temp folder or something.
Can anyone help me out?
Code is:
//IMAGE FILE
$file_name = $_FILES['product_img']['name'];
echo '<p>File Name:' . $file_name . '</p>';
//IMAGE UPLOAD
// random 4 digit to add to file name
$random_digit=rand(0000,9999);
//combine random digit to file name to create new file name
//use dot (.) to combile these two variables
$new_image_name = $random_digit.$file_name;
echo $new_image_name;
//SET DESINATION FOLDER
$path= "uploads/".$new_image_name;
echo '<p>Path:' . $path . '</p>';
if($product_img !=none)
{
if(copy($HTTP_POST_FILES['product_img']['tmp_name'], $path))
{
echo "Successful<BR/>";
echo "File Name :".$new_file_name."<BR/>";
echo "File Size :".$HTTP_POST_FILES['product_img']['size']."<BR/>";
echo "File Type :".$HTTP_POST_FILES['product_img']['type']."<BR/>";
}
else
{
echo "Image upload Error<BR/>";
}
}
Any help would be greatly appreciated!
Thanks