Text after "
.
$ file = I use this piece of code to create thumbnails of an uploaded image = RandString (). '. Jpg '; $ UNIPELE = 'I / U'. $ Login; $ Full path = $ UniPath '/ A /' $ File; $ ThumbPath = $ uniPath '/ B /' $ File; If (copy ($ _ FILES [ 'file'] [ 'tmp_name'], $ completePath)) {function convertPic ($ w_dst, $ h_dst, $ n_img) {$ wxh = $ w_dst.'x '$ h_dst. Switch ($ wxh) {case '150x150': $ letters = 'b'; break; Case '50x50': $ letters = 'c'; break; Default: $ letters = 'z'; } $ DbPath = '/i/u1/'.$letter.' '' '.nn_img; $ New_img = $ _SERVER ['DOCUMENT_ROOT']. $ DbPath; $ File_src = "img.jpg"; // Temporary Secure Image Storage $ img_src = $ file_src; ($ File_src) Unlink; Move_uploaded_file ($ _ files ['filename'] ['tmp_name'], $ file_src); List ($ w_src, $ h_src, $ type) = getimagesize ($ file_src); // Create a new dimension, keeping aspect ratio $ proportion = $ w_src / $ h_src; $ H_ratio = ($ h_dst / $ h_src); $ W_ratio = ($ w_dst / $ w_src); If ($ w_src & gt; $ h_src) {// Landscape $ w_crop = round ($ w_src * $ h_ratio); $ H_crop = $ h_dst; $ Src_x = seat (($ w_src - $ h_src) / 2); $ Src_y = 0; } Otherwise ($ w_src & lt; $ h_src) {// Portrait $ h_crop = round ($ h_src * $ w_ratio); $ W_crop = $ w_dst; $ Src_y = seat (($ h_src - $ w_src) / 2); $ Src_x = 0; } Else {// class $ w_crop = $ w_dst; $ H_crop = $ h_dst; $ Src_x = 0; $ Src_y = 0; } Switch ($ type) {case 1: // gif - & gt; Jpg $ img_src = imagecreatefromgif ($ file_src); break; Case 2: // jpeg - & gt; Jpg $ img_src = imagecreatefromjpeg ($ file_src); break; Case 3: // PNG - & gt; Jpg $ img_src = imagecreatefrompng ($ file_src); break; } $ Img_dst = imagecreatetruecolor ($ w_dst, $ h_dst); // resample imagecolorallocate ($ img_dst, 255, 255, 255) or die ("delete image color"); imagecopyresampled ($ img_dst, $ img_src, 0, 0, $ src_x, $ src_y, $ w_crop, $ h_crop, $ w_src, $ h_src) or die ( "imagecopyresampled ($ img_dst, $ img_src, 0, 0, $ src_x, $ Src_y, $ w_crop, $ h_crop, $ w_src, $ h_src) "); Imagejpeg ($ img_dst, $ new_img); // Save new image unlink ($ file_src); // image storage imagedestroy clean ($ img_src); Imagedestroy ($ img_dst); Return $ db_path; } Convert picture (150, 150, $ file); Convert picture (250, 250, $ file); But for some reason convert PIC function does not work if the above example is called twice if it is called then everything works fine Does. I put a warning, then imagecopyresampled fails and output imagecopyresampled (process ID # 17, img.jpg, 0, 0, 0, 0, 250, 250 ,,),
I think the problem is with temporary image storage, but not sure. help please.
I think with that problem unlink ($ file_src) is ... < P> First of all, you call the convertPic () function and it works fine because your img.jpg is still here, then you can delete the image with unlink < / Code> and try to call again the same routine that really needs this file to work properly. In addition, you can not move the same file twice, then you need to do so many times as your work, to move out of the function, and after that, the image Unlink to Unlink convertPic () before the convert picture () , and move_uploaded_file () should be after the double call. Well, at first glance, I find that.
Comments
Post a Comment