I'm very new to php and I'm working on an upload script. I want it to assign the uploaded file a random name and then save it in a specific directory on the server. For some reason when this code is executed it says that the file already exists. What is causing this?
Here's the code:
Code:<?php $name = rand(100, 10000000000000); if (($_FILES["file"]["size"] < 2000000000)) { if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br/>"; } else { echo "Upload: " . $_FILES["file"]['$name'] . "<br/>"; echo "Type: " . $_FILES["file"]["type"] . "<br/>"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " KB<br/>"; echo "Stored in: " . $_FILES["file"]['$name']; } if (file_exists("upload/" . $_FILES["file"]['$name'])) { echo $_FILES["file"]['$name'] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]['$name']); echo "Stored in: " . "upload/" . $_FILES["file"]['$name']; } } else { echo "Invalid file"; } ?>




Reply With Quote