Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to upload images to folder
    text
    copied!<p>Can you please help me and tell me how I can get the images to be uploaded to a certain folder using the below script.</p> <p>I want the full images to be saved to imagefolder and the thumbnails to be saved to inside the imagefolder.</p> <p>The code is below.</p> <pre><code>&lt;?php $upload_image_limit = 5; // How many images you want to upload at once? $upload_dir = ""; // default script location, use relative or absolute path $enable_thumbnails = 1 ; // set 0 to disable thumbnail creation $max_image_size = 1024000 ; // max image size in bytes, default 1MB ##################### THUMBNAIL CREATER FROM GIF / JPG / PNG function make_thumbnails($updir, $img){ $thumbnail_width = 80; $thumbnail_height = 60; $thumb_preword = "thumb_"; $arr_image_details = GetImageSize("$updir"."$img"); $original_width = $arr_image_details[0]; $original_height = $arr_image_details[1]; if( $original_width &gt; $original_height ){ $new_width = $thumbnail_width; $new_height = intval($original_height*$new_width/$original_width); } else { $new_height = $thumbnail_height; $new_width = intval($original_width*$new_height/$original_height); } $dest_x = intval(($thumbnail_width - $new_width) / 2); $dest_y = intval(($thumbnail_height - $new_height) / 2); if($arr_image_details[2]==1) { $imgt = "ImageGIF"; $imgcreatefrom = "ImageCreateFromGIF"; } if($arr_image_details[2]==2) { $imgt = "ImageJPEG"; $imgcreatefrom = "ImageCreateFromJPEG"; } if($arr_image_details[2]==3) { $imgt = "ImagePNG"; $imgcreatefrom = "ImageCreateFromPNG"; } if( $imgt ) { $old_image = $imgcreatefrom("$updir"."$img"); $new_image = imagecreatetruecolor($thumbnail_width, $thumbnail_height); imageCopyResized($new_image,$old_image,$dest_x, $dest_y,0,0,$new_width,$new_height,$original_width,$original_height); $imgt($new_image,"$updir"."$thumb_preword"."$img"); } } ################################# UPLOAD IMAGES foreach($_FILES as $k =&gt; $v){ $img_type = ""; ### $htmo .= "$k =&gt; $v&lt;hr /&gt;"; ### print_r($_FILES); if( !$_FILES[$k]['error'] &amp;&amp; preg_match("#^image/#i", $_FILES[$k]['type']) &amp;&amp; $_FILES[$k]['size'] &lt; $max_image_size ){ $img_type = ($_FILES[$k]['type'] == "image/jpeg") ? ".jpg" : $img_type ; $img_type = ($_FILES[$k]['type'] == "image/gif") ? ".gif" : $img_type ; $img_type = ($_FILES[$k]['type'] == "image/png") ? ".png" : $img_type ; $img_rname = $_FILES[$k]['name']; $img_path = $upload_dir.$img_rname; copy( $_FILES[$k]['tmp_name'], $img_path ); if($enable_thumbnails) make_thumbnails($upload_dir, $img_rname); $feedback .= "Image and thumbnail created $img_rname&lt;br /&gt;"; } } ############################### HTML FORM while($i++ &lt; $upload_image_limit){ $form_img .= '&lt;label&gt;Image '.$i.': &lt;/label&gt; &lt;input type="file" name="uplimg'.$i.'"&gt;&lt;br /&gt;'; } $htmo .= ' &lt;p&gt;'.$feedback.'&lt;/p&gt; &lt;form method="post" enctype="multipart/form-data"&gt; '.$form_img.' &lt;br /&gt; &lt;input type="submit" value="Upload Images!" style="margin-left: 50px;" /&gt; &lt;/form&gt; '; echo $htmo; ?&gt; </code></pre> <p>Thank you. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload