dropbop Posted October 30, 2011 Share Posted October 30, 2011 I have looked around all overr, but cant find what im looking for. Everything I have found is about uploading multile files, what I need to do is upload one file and copy it so there is 3 files. Here is an example of what I need to accomplish. Upload file picture1.jpg From picture1.jpg create 3 files - smallimage_picture1.jpg, largeimage_picture1.jpg & smallimage_picture1_thumb.jpg Each file will need to be copied to a /products directory and also an entry for each file name placed in mysql database table. I don't think this is as simple as it sounds to do in PHP, but i am very willing to learn so if anyone knows of a good tutorial that get get me started that would be super. regards DB Quote Link to comment https://forums.phpfreaks.com/topic/250116-upload-one-file-and-create-multiple-files/ Share on other sites More sharing options...
AyKay47 Posted October 30, 2011 Share Posted October 30, 2011 look into using GD functions with PHP to create thumbnails of the file.. Quote Link to comment https://forums.phpfreaks.com/topic/250116-upload-one-file-and-create-multiple-files/#findComment-1283464 Share on other sites More sharing options...
jcbones Posted October 30, 2011 Share Posted October 30, 2011 The easiest way is to get SimpleImage. Then build a script. <?php include 'simpleImage.php'; //include the class. $filePath = 'upload/images/'; //set file path. $imageName = 'myImage.jpg'; //set image name. if(!$upload_errors) { //after all error checks. $image = new SimpleImage(); //start the class. $image->load($_FILES['image']['tmp_name']); //load the temp file. $image->save($filePath . $imageName); //save the image, will be the large pic. $image->resize(200,200); //resize the image to the smaller size. $image->save($filePath . 'small_' . $imageName); //save the smaller pic, added 'small' to the name. $image->resize(50,50); //resize to thumbnail size. $image->save($filePath . 'tmb_' . $imageName); //save the thumbnail, added tmb to the name. This code should work, but is in no way good for public use. There should be lots of other checks in there. This is just to get you started. Quote Link to comment https://forums.phpfreaks.com/topic/250116-upload-one-file-and-create-multiple-files/#findComment-1283498 Share on other sites More sharing options...
dropbop Posted October 31, 2011 Author Share Posted October 31, 2011 ok, so I have managed to get the basics going.... <?php if(isset($_POST['Submit'])) { $current_image=$_FILES['image']['name']; $extension = substr(strrchr($current_image, '.'), 1); if (($extension!= "jpg") && ($extension != "jpeg")) { die('Unknown extension'); } $time = date("fYhis"); $new_image = "image_large_" . $time . "." . $extension; $new_image_small = "image_small_" . $time . "." . $extension; $destination="uploads/".$new_image; $destinationtwo="uploads/".$new_image_small; $action = copy($_FILES['image']['tmp_name'], $destination); $action = copy($_FILES['image']['tmp_name'], $destinationtwo); if (!$action) { die('File copy failed'); }else{ mysql_query("INSERT INTO customers (small_image, large_image) VALUES ('".$new_image_small."','".$new_image."')"); echo "File copy successful"; } ?> This works so far but is still a bit basic compared to what I need. Here I can upload a file, then save it as 2 files with different name in the uploads folder, and also add the names to the database. What I need to do now, is make one image small (approx 200px) and the other one large (Approx 600px). I have looked at that Simpleimage (Thanks jcbones) but it confuses me, is there a simpler way to change the size of an image that a bit less complicated for me? Thanks Eoin Quote Link to comment https://forums.phpfreaks.com/topic/250116-upload-one-file-and-create-multiple-files/#findComment-1283828 Share on other sites More sharing options...
jcbones Posted November 2, 2011 Share Posted November 2, 2011 Simple image is much easier than doing it any other way, that is why it is called "Simple Image". My snippet runs hand in hand, minus the database query, with what you just did. It is fully commented. Quote Link to comment https://forums.phpfreaks.com/topic/250116-upload-one-file-and-create-multiple-files/#findComment-1284365 Share on other sites More sharing options...
dropbop Posted November 2, 2011 Author Share Posted November 2, 2011 Simple image is much easier than doing it any other way, that is why it is called "Simple Image". My snippet runs hand in hand, minus the database query, with what you just did. It is fully commented. I'm actually looking back into it again.. After looking at loads of other ways to resize images, Simple Image seems to be the best.. Thanks jcbones Quote Link to comment https://forums.phpfreaks.com/topic/250116-upload-one-file-and-create-multiple-files/#findComment-1284382 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.