--- Wade Smart <[EMAIL PROTECTED]> wrote: > Going through the forums on several sites Im not the only one having > this problem. And its still confusing as some say that the second > parameter is a file name and some say its a destination. And it seems to > work either way for many - which I dont understand that at all. > > I simplified this out to just: > $saveTo = "new_picts/" > $saveAs = "NewFile.png" > > and tried > imagepng($img_handle, $saveTo) and imagepng($img_handle. $saveAs); > and neither work. Adding in the third and four parmeter as several posts > say you must have, I added 0, NULL but that didnt help either. > > As for right now, only imagepng($img_handle); seems to work. > > Wade
Note that the documentation (http://php.net/imagepng) indicates that you can output an image OR save an image. The same function call cannot do both. You will have to call it twice -- once to save and once to output the image to the browser. The second parameter for saving the image is expecting a path and filename (eg "thumbs/mypic.png" or /var/www/user/thumbs/mypic.png"). Probably the relative path (first example) is best since it allows some flexibility and should keep it working even if your host moves things around for your account. The directory where the images will be saved must be writable by the web server. With Apache on Linux this may be the user named "apache" or "nobody" or something else. *** Having a writable directory in the web space can be very dangerous because it allows an outside user an opportunity to put content on your server and run it *** With that in mind, you may want your writable directory to be outside of your web space. On my host, for example, my "home" directory has a public_html directory which contains all of the files that can be accessed by Apache's configuration. Other files and directories at the home directory level cannot be reached by Apache (by configuration) but can be accessed by PHP functions if given a proper path. Check with your sysadmins about setting permissions and creating such a directory. You will need to have a PHP handler script which can obtain these files in a controlled (ie authorized and safe) manner. More than likely, the reason why your function does not seem to work when you add a second parameter is that if you give a filename only, the directory where your PHP script is running is not (and should not be) writable by Apache. You don't see the error message because the browser has received the image/png MIME type and is expecting binary image data. This is where sending errors to a log file can be very helpful. James