SwapsRulez Posted June 21, 2008 Share Posted June 21, 2008 Hi there, i'm working for an application where i do need to create an upload page where user can upload the .swf files only & that file must be less than or equal to 5 mb. i've created the site using html. but i'm new to php & that's why searched it on the google. it returned the following code... <?php //Сheck that we have a file if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) { //Check if the file is JPEG image and it's size is less than 350Kb $filename = basename($_FILES['uploaded_file']['name']); $ext = substr($filename, strrpos($filename, '.') + 1); if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") && ($_FILES["uploaded_file"]["size"] < 350000)) { //Determine the path to which we want to save this file $newname = dirname(__FILE__).'/upload/'.$filename; //Check if the file with the same name is already exists on the server if (!file_exists($newname)) { //Attempt to move the uploaded file to it's new place if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) { echo "It's done! The file has been saved as: ".$newname; } else { echo "Error: A problem occurred during file upload!"; } } else { echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists"; } } else { echo "Error: Only .jpg images under 350Kb are accepted for upload"; } } else { echo "Error: No file uploaded"; } ?> What do i need to change to make this work for the php files. Waiting for the reply. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
advancedfuture Posted June 21, 2008 Share Posted June 21, 2008 //Сheck that we have a file if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) { //Check if the file is PHP file and it's size is less than 5Mb $filename = basename($_FILES['uploaded_file']['name']); $ext = substr($filename, strrpos($filename, '.') + 1); if (($ext == "swf") && ($_FILES["uploaded_file"]["size"] < 5000000)) { //Determine the path to which we want to save this file $newname = dirname(__FILE__).'/upload/'.$filename; //Check if the file with the same name is already exists on the server if (!file_exists($newname)) { //Attempt to move the uploaded file to it's new place if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) { echo "It's done! The file has been saved as: ".$newname; } else { echo "Error: A problem occurred during file upload!"; } } else { echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists"; } } else { echo "Error: Only .php files under 5Mb are accepted for upload"; } } else { echo "Error: No file uploaded"; } ?> Quote Link to comment Share on other sites More sharing options...
SwapsRulez Posted June 21, 2008 Author Share Posted June 21, 2008 Its telling me that no file uploaded. I got that script from some random site. But when i run it on localhost. Its giving me the error that, Error: No file uploaded How should i write the code so that i can get a browse button & upload button for uploading a swf file. btw thanks for looking to the code & taking the interest in solving the problem. Quote Link to comment Share on other sites More sharing options...
advancedfuture Posted June 21, 2008 Share Posted June 21, 2008 Here's a basic example: <h1 align="center">SWF Upload</h1> <form enctype="multipart/form-data" method="post" action=""> <input type="hidden" name="MAX_FILE_SIZE" value="5000000" /> Choose SWF File To Upload: <input name="uploadedfile" type="file" id="uploadedfile" size="50" /> <input type="submit" name="submit" value="submit" /> </form> <?php if($_POST['submit']) { $target_path = "upload/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> Quote Link to comment Share on other sites More sharing options...
SwapsRulez Posted June 21, 2008 Author Share Posted June 21, 2008 Donno what happened, but its giving me error Parse error: syntax error, unexpected $end in C:\xampp\htdocs\upload.php on line 15 I tried running single file. But giving same error. I checked out the code, but there is no $end symbol in the code. Then i made 2 files. First one is upload.html where i inserted html code & then upload.php where i've placed php code & made action="upload.php" But still i'm getting the above error. Thanks soo much. But still there is some problem. Waiting for your reply. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 It means you've missed a } in your code somewhere. =P Quote Link to comment Share on other sites More sharing options...
SwapsRulez Posted June 21, 2008 Author Share Posted June 21, 2008 It means you've missed a } in your code somewhere. =P Thanks mate.. problem solved. Perfect Solution for the problem. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 No problem. =) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.