Alkimuz Posted September 26, 2008 Share Posted September 26, 2008 Hey, i want to save an uploaded picture to two different locations, is that possible? if so, how? now, i let a user upload a picture and my code resizes the picture and stores it at a specific location, but i like to resize it for a second time and store that picture at a second location, but it seems that if i run the uploadcode twice, the original temporary sourcedata ( where $_FILES[$filename]['tmp_name'] points to) is deleted? the code i use at the moment is the following, any suggestions how i can expand it, or repeat it so that it resizes the original picture twice and stores it twice? function photoupload($filename, $source, $path, $name, $MaxX, $MaxY) { /*START PHOTOUPLOAD*/ if (trim($_FILES[$filename]['tmp_name']) == TRUE) { $destination = $path.$name.'-'.$_FILES[$filename]['name'] ; // Does the file have the right MIME type? if ($_FILES[$filename]['type'] != 'image/pjpeg' AND $_FILES[$filename]['type'] != 'image/jpeg' AND $_FILES[$filename]['type'] != 'image/gif' AND $_FILES[$filename]['type'] != 'image/png' AND $_FILES[$filename]['type'] != 'image/wbmp') { echo 'the file you want to upload is no photo, please go back to try again'; exit; } // Get current dimensions list($width_orig, $height_orig) = getimagesize($source); // Check if they are over their limit if ( ($width_orig > $MaxX) || ( $height_orig > $MaxY)) { if ($MaxX && ($width_orig < $height_orig)) { $MaxX = ($MaxY / $height_orig) * $width_orig; } else { $MaxY = ($MaxX / $width_orig) * $height_orig; } // Resample voorbereiden $image_p = imagecreatetruecolor($MaxX, $MaxY); $image_type = strtolower( substr($destination, strrpos( $destination, '.' )) ); switch( $image_type ) { case '.gif' : $image = imagecreatefromgif($source); break; case '.jpg' : $image = imagecreatefromjpeg($source); break; case '.jpeg': $image = imagecreatefromjpeg($source); break; case '.png' : $image = imagecreatefrompng($source); break; case '.bmp' : $image = imagecreatefromwbmp($source); break; } // Resample de afbeelding imagecopyresampled($image_p, $image, 0, 0, 0, 0, $MaxX, $MaxY, $width_orig, $height_orig); // Output switch( $image_type) { case '.gif' : imagegif($image_p, $source, 100); break; case '.jpg' : imagejpeg($image_p, $source, 100); break; case '.jpeg' : imagejpeg($image_p, $source, 100); break; case '.png' : imagepng($image_p, $source, 100); break; case '.bmp' : image2wbmp($image_p, $source, 100);break; } move_uploaded_file ( $source, $destination ); } else { // Image is ok, just move it to the new location move_uploaded_file ( $source, $destination ); } return 0; } /*END PHOTOUPLOAD*/ } Link to comment https://forums.phpfreaks.com/topic/125983-solved-upload-a-file-twice/ Share on other sites More sharing options...
amagondes Posted September 26, 2008 Share Posted September 26, 2008 hi, i'm pretty sure when you call move_uploaded_file, it does actually move the file, so your second call will not be able to find it (beacuse it has been moved). Why don't you pass the file name of first saved image to the second call as I'm guessing that is what the $source paramater is in the function declaration. hope that helps Link to comment https://forums.phpfreaks.com/topic/125983-solved-upload-a-file-twice/#findComment-651601 Share on other sites More sharing options...
JasonLewis Posted September 26, 2008 Share Posted September 26, 2008 You can use copy() to copy the file to a new location. Link to comment https://forums.phpfreaks.com/topic/125983-solved-upload-a-file-twice/#findComment-651608 Share on other sites More sharing options...
Alkimuz Posted September 27, 2008 Author Share Posted September 27, 2008 thanks! both of you! amagondes for making me help to understand why it didnt work projectfear for the golden tip for making my code work! i didnt know the function copy, so know i do, it was not a hard job to change my not working code to a working one thanks again ^^ Link to comment https://forums.phpfreaks.com/topic/125983-solved-upload-a-file-twice/#findComment-651657 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.