atomicrabbit Posted December 9, 2009 Share Posted December 9, 2009 Ok so I have a form that requires the user to upload an image, and then do something with that image (using some ajax scripts), then fill out the rest of the form and submit. I have the upload script pretty much working, my problem is that I need to store the uploaded images temporarily just in case the user decides not to submit the form Here's the process I would need: 1) Form loads 2) User fills out form 3) User uploads image (php + ajax) a) image is resized to a large and thumbnail image using imagecopyresampled() b) fullsize and thumbnail images should be stored in a temporary location ?? 4) Image is dynamically displayed in the form after upload and resize (using some jQuery/ajax magic) 5) User performs some action to the uploaded image (using jQuery/ajax) At this point, the user can submit the completed form, at which time a php script will will move the temporary (resized) fullsize and thumbnail images from the temp location to a permanent location on the server, and if the file saving succeeds, then it will write the form data to a MySQL server. BUT if the user doesn't submit the form, I need the temporary files to be deleted. Normally this would be handled by the temporary files being stored by the $_FILES array, but since I have to resize them after upload, the $_FILES["upload"]["tmp_name"] is automatically deleted after I resize it. Please suggest an alternative solution. As I said, the upload script is done. It can upload and resize the images, but I need a way to store the images temporarily until the form is submitted. Link to comment https://forums.phpfreaks.com/topic/184552-image-upload-resize-then-submit-form/ Share on other sites More sharing options...
atomicrabbit Posted December 9, 2009 Author Share Posted December 9, 2009 I should note that currently, I'm storing the image data temporarily in a $_SESSION variable, which is not really a good idea because binary/image data can get large. It's just a temporary solution until I can figure out a better way. Link to comment https://forums.phpfreaks.com/topic/184552-image-upload-resize-then-submit-form/#findComment-974320 Share on other sites More sharing options...
atomicrabbit Posted December 9, 2009 Author Share Posted December 9, 2009 anyone? Link to comment https://forums.phpfreaks.com/topic/184552-image-upload-resize-then-submit-form/#findComment-974400 Share on other sites More sharing options...
flafaille Posted December 10, 2009 Share Posted December 10, 2009 http://www.php.net/manual/en/function.move-uploaded-file.php Link to comment https://forums.phpfreaks.com/topic/184552-image-upload-resize-then-submit-form/#findComment-974459 Share on other sites More sharing options...
atomicrabbit Posted December 10, 2009 Author Share Posted December 10, 2009 right, but move_uploaded_file() only works on files that already exist on the server (such as $_FILES["upload"]["tmp_name"]). The problem is, as soon as the file is uploaded, my php script resizes it using imagecopyresampled() and then saves the image to a php variable. I need to be able to temporarily store the resized image somewhere so that when the form is submitted, I can save the resized images to a permanent place on the server. Link to comment https://forums.phpfreaks.com/topic/184552-image-upload-resize-then-submit-form/#findComment-974502 Share on other sites More sharing options...
atomicrabbit Posted December 10, 2009 Author Share Posted December 10, 2009 any help? Link to comment https://forums.phpfreaks.com/topic/184552-image-upload-resize-then-submit-form/#findComment-974743 Share on other sites More sharing options...
atomicrabbit Posted December 10, 2009 Author Share Posted December 10, 2009 Ok I've been looking on these forums and found this thread: http://www.phpfreaks.com/forums/index.php/topic,279777.0.html Basically I'm looking to create a temporary file that will hold my images until I move them to a permanent location, OR automatically delete them when the script is done if they weren't moved. I.E. if the user closes the browser or leaves the page, or refreshes the page, the server will automatically delete them. I did a bit of research and found two php function, tempnamtmpfile] and tmpfile. tmpfile creates a file with a unique name and passes back the file handle. It basically creates the file and automatically fopen's it. It get deleted when you run fclose. tempnam creates a temporary file with a unique filename and 0600 permissions, in the path you give it and returns the path of the file. In the forum thread I linked to above, the OP was explaining how php file uploads work with temporary files. Basically if the temporary is not moved or the move_uploaded_files function fails, the temporary files is automatically deleted after the script finishes... so no extra function is needed to be called. I need a way to write a temporary file like this, in that it will automatically get deleted if the script finishes and it still exists in the temporary directory. Link to comment https://forums.phpfreaks.com/topic/184552-image-upload-resize-then-submit-form/#findComment-974817 Share on other sites More sharing options...
andrew101 Posted December 10, 2009 Share Posted December 10, 2009 thanks for all the help guys, i solve the problem. Link to comment https://forums.phpfreaks.com/topic/184552-image-upload-resize-then-submit-form/#findComment-975098 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.