Reputation: 89
So my image gets uploaded without issues but what is this error I get after image gets uploaded on form submit?
This is the bit of my php:
if(isset($_POST['submit'])){
if($_FILES['file']['name']!='')
{
$tmp_name = $_FILES["file"]["tmp_name"];
$namefile = $_FILES["file"]["name"];
$ext = end(explode(".", $namefile)); //line 16
$fileUpload = move_uploaded_file($tmp_name,"blogUploads\images/".$image_name); //line 17
$image_name=time().".".$ext;
watermark_image($tmp_name,"blogUploads\images/".$image_name);
$img = ''.$image_name.'';
}else{
$img = '';
}
}
Upvotes: 0
Views: 71
Reputation: 4504
for error :"filename strict standards only variables should be passed by reference" in end(explode())
1st Assign the result of explode Array into a variable and then pass that variable to end like:
$tmp = explode('.', $namefile);
$file_extension = end($tmp);
or
$path_parts = pathinfo($filename);
$extension = $path_parts['extension'];
$fileName = $path_parts['filename'];
2nd for move_uploaded_file() error just ensure that destination path(2nd parameter) is valid (plus ensure that your upload folder has write permissions )
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
follow "Complete Upload File PHP Script" from
http://w3schools.com/php/php_file_upload.asp
PS:also assignment of $image_name variable should before move_uploaded_file()
Upvotes: 1
Reputation: 116
Correct your directory structure on line 17 by this :
$fileUpload = move_uploaded_file($tmp_name,"blogUploads\images\".$image_name);; //line 17
and here also
watermark_image($tmp_name,"blogUploads\images\".$image_name);
Upvotes: 1