Note that there are some explanatory texts on larger screens.

plurals
  1. PORename file when upload in php
    primarykey
    data
    text
    <p>I'm making simple file uploading script right now. Everything works well, but when I upload another file with same - script just overwrites it. So, what I want is to be able rename each uploaded file to random name. (Ex. 12jfisfhassa .extension).</p> <p>Here's what I have so far:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;File Uploader v1.0&lt;/title&gt; &lt;link rel='stylesheet' href='style.css'&gt; &lt;/head&gt; &lt;body&gt; &lt;center&gt; &lt;table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"&gt; &lt;tr&gt; &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="POST" enctype="multipart/form-data"&gt; &lt;td&gt; &lt;table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"&gt; &lt;tr&gt; &lt;b&gt;Please choose a file:&lt;/b&gt;&lt;br/&gt; &lt;input type="file" name="fileup"/&gt;&lt;br/&gt; &lt;br/&gt; &lt;input type="submit" name='submit' value="Upload"/&gt; &lt;/tr&gt; &lt;/form&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; &lt;?php $uploadpath = 'upload/'; // directory to store the uploaded files $max_size = 103000000; // maximum file size, in KiloBytes $allowtype = array('bmp', 'gif', 'jpg', 'jpe', 'png', 'rar', 'zip', 'exe'); // allowed extensions if(isset($_FILES['fileup']) &amp;&amp; strlen($_FILES['fileup']['name']) &gt; 1) { $uploadpath = $uploadpath . basename( $_FILES['fileup']['name']); // gets the file name $sepext = explode('.', strtolower($_FILES['fileup']['name'])); $type = end($sepext); // gets extension list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']); // gets image width and height $err = ''; // to store the errors // Checks if the file has allowed type, size, width and height (for images) if(!in_array($type, $allowtype)) $err .= 'The file: &lt;b&gt;'. $_FILES['fileup']['name']. '&lt;/b&gt; not has the allowed extension type.'; if($_FILES['fileup']['size'] &gt; $max_size*1000) $err .= '&lt;br/&gt;Maximum file size must be: '. $max_size. ' KB.'; // If no errors, upload the image, else, output the errors if($err == '') { if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) { echo '&lt;font color="green"&gt;&lt;b&gt;Success!&lt;/b&gt;&lt;/font&gt;'; echo '&lt;br/&gt;File: &lt;b&gt;'. basename( $_FILES['fileup']['name']). '&lt;/b&gt;'; echo '&lt;br/&gt;File type: &lt;b&gt;'. $_FILES['fileup']['type'] .'&lt;/b&gt;'; echo '&lt;br /&gt;Size: &lt;b&gt;'. number_format($_FILES['fileup']['size']/1024, 3, '.', '') .'&lt;/b&gt; KB'; echo '&lt;br/&gt;&lt;br/&gt;File path: &lt;input type="text" value="http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$uploadpath.'" readonly&gt;'; } else echo '&lt;b&gt;Unable to upload the file.&lt;/b&gt;'; } else echo $err; } ?&gt; &lt;/center&gt; </code></pre> <p>And yeah, I don't use mysql. Please help? :)</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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