Reputation: 1305
So Im trying to make a script that uses PHP GD to upload and resize an image. Then save it to the database. I used the SImpleImage.php found here:
http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/
And implemented the code using the following script:
$myfilename=$_POST['attachments'];
require('SimpleImage.php');
$image = new SimpleImage();
$image->load($myfilename);
$image->resizeToWidth(150);
$image->save('small-'.$myfilename);
$image->load($myfilename);
$image->resizeToWidth(230);
$image->save('big-'.$myfilename);
myfilename is a variable attached to a form field. Ive been playing about with it, and made sure my server has GD installed, and that the SimpleImage.php file is uploaded correctly. But I keep getting loads of errors.
Warning: imagesy(): supplied argument is not a valid Image resource in (File Path).php on line 77
All of them relating to SimpleImage.php, which I did not write, seems like it makes sense, and that I know other people have implemented successfully. The majority of the errors are to the one above. Does anyone have any ideas where this problem may be stemming from?
Upvotes: 0
Views: 136
Reputation: 292
You can't get a file from a HTML form with $_POST. To upload a file you need this field in your form:
<input type="file" name="attachments">
In your PHP script you have to change the first line:
$myfilename=$_FILES['attachments']['tmp_name'];
Upvotes: 3