Jump to content

Upload one file and create multiple files


dropbop

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.