Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple file upload in PHP - rename files
    primarykey
    data
    text
    <p>I'm a beginner in php and now doing a project in php. I want to upload images(maximum four image files only).I used the following code to upload images.</p> <pre><code>&lt;script type="text/javascript"&gt; count=1; function add_file_field() { if(count&lt;4) { var container=document.getElementById('file_container'); var file_field=document.createElement('input'); file_field.name='images[]'; file_field.type='file'; container.appendChild(file_field); var br_field=document.createElement('br'); container.appendChild(br_field); count++; } } &lt;/script&gt; &lt;div id="file_container"&gt; &lt;input name="images[]" type="file" id="file[]" /&gt; &lt;br /&gt; &lt;/div&gt; &lt;br&gt;&lt;a href="javascript:void(0);" onClick="add_file_field();"&gt;Add&lt;/a&gt; </code></pre> <p></p> <p>I used the following code for single file upload.It's working</p> <pre><code>&lt;?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) &amp;&amp; ($_FILES["file"]["size"] &lt; 100000)) { if ($_FILES["file"]["error"] &gt; 0) { echo "File Error : " . $_FILES["file"]["error"] . "&lt;br /&gt;"; }else { echo "Upload File Name: " . $_FILES["file"]["name"] . "&lt;br /&gt;"; echo "File Type: " . $_FILES["file"]["type"] . "&lt;br /&gt;"; echo "File Size: " . ($_FILES["file"]["size"] / 1024) . " Kb&lt;br /&gt;"; echo "File Description:: ".$_POST['description']."&lt;br /&gt;"; if (file_exists("images/".$_FILES["file"]["name"])) { echo "&lt;b&gt;".$_FILES["file"]["name"] . " already exists. &lt;/b&gt;"; }else { $tmpname=$_FILES["file"]["tmp_name"]; $name=$_FILES["file"]["name"]; $new="jun.jpg"; rename($name,$new); move_uploaded_file($_FILES["file"]["tmp_name"],"images/".$new); echo "Stored in: " . "images/" .$new."&lt;br /&gt;"; ?&gt; Uploaded File:&lt;br&gt; &lt;img src="images/&lt;?php echo $new; ?&gt;" alt="Image path Invalid" &gt; &lt;?php } } }else { echo "Invalid file detail ::&lt;br&gt; file type ::".$_FILES["file"]["type"]." , file size::: ".$_FILES["file"]["size"]; } ?&gt; </code></pre> <p>I need help to modify this code to upload maximum of 4 images. Can rename function be used to rename a selected file for upload on moving to a specified folder? but it was showing error</p> <p>Please do help me</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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