php - move_uploaded_file: not allowed to use tmp_name? -


question:

when use move_uploaded_file function, can keep name created in tmp_name? or must change name else?

if can keep name of file moving tmp_name, how must pass in argument? tried following code, , can't seem work.

please see code below:

if(isset($_post['submit'])){     $tmp_file = $_files['file_upload']['tmp_name'];     $target_file = basename($_files['file_upload']['name']);     $upload_dir = "uploads";      if(move_uploaded_file($tmp_file, $upload_dir."/".$tmp_file)){         $message = "file uploaded successfully.";     }else{         $error = $_files['file_upload']['error'];         $message = $upload_errors[$error];     } } 

when pass second argument in $upload_dir."/".$target_file , there doesn't seem issues, when pass $upload_dir."/".$tmp_file shown in codes above, keeps giving me following error:

scream: error suppression ignored for

warning: move_uploaded_file(uploads/c:\wamp\tmp\php1ea0.tmp): failed open stream: invalid argument in c:\wamp\www\bb2\uploads.php on line 26 

tmp_name not file name, it's full path file.

if want random filename, suggest code this:

$dest = $_files['file_upload']['name']; while (file_exists($dest)) {   $dest = $upload_dir . '/' . substr(sha1(rand()), 0, 10); }  move_uploaded_file($_files['file_upload']['name'], $dest); 

rand() generates random big number. sha1() uses seed create bigger random hex string, don't want big grab first 10 characters or so.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -