Warptweet Posted January 4, 2007 Share Posted January 4, 2007 I have an uploader form. And theres a problem, it gives me an error.go to www.warptweet.com/uploadflash.phpIt will take you to a form, try uploading a .swf (flash) file, and it will give you an error.Here is the code[code]<?phpif (($_FILES["file"]["type"] == "application/x-shockwave-flash") && ($_FILES["file"]["size"] < $_POST['MAX_FILE_SIZE'])) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; echo "Uploading " . $_FILES["file"]["name"]; echo " (" . $_FILES["file"]["type"] . ", "; echo ceil($_FILES["file"]["size"] / 1024) . " Kb).<br />"; if (file_exists("uploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; echo "Please delete the destination file and try again."; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]); echo "File has been stored in your uploads directory."; $flashname = $_POST['flashname']; $flashauthor = $_POST['flashauthor']; $flashdescription = $_POST['flashdescription']; $ourFileName = $_POST['uploadedfile']; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); rename($ourFileName, substr($ourFileName, 0, strrpos($ourFileName,'.')).'.txt'); fclose($ourFileName); $fh = fopen($ourFileName, 'w') or die("can't open file"); $stringData = $flashname; fwrite($fh, $stringData); fclose($fh); }} else echo "Warptweet.com Error Returned: Only .swf flash files under 20MB may be uploaded.";?> [/code]Can anyone tell me whats wrong? Or improvise on my code? Link to comment https://forums.phpfreaks.com/topic/32822-code-not-working/ Share on other sites More sharing options...
448191 Posted January 4, 2007 Share Posted January 4, 2007 You can't open $ourFileName after you rename it.. ::) Use the new filename.Oh, and you can't rename an open file! Link to comment https://forums.phpfreaks.com/topic/32822-code-not-working/#findComment-152822 Share on other sites More sharing options...
Warptweet Posted January 4, 2007 Author Share Posted January 4, 2007 zomg! I've made some bad mistakes! :o lolWait... If I close $ourFileName, will I still be able to rename it using $ourFileName? How will I be able to call that file back after renaming it in order to write things on it? Link to comment https://forums.phpfreaks.com/topic/32822-code-not-working/#findComment-152824 Share on other sites More sharing options...
448191 Posted January 4, 2007 Share Posted January 4, 2007 I am absolutely clueless as to why you would want to change .swf to .txt and then add some string to it, but hey, it's your party:[code]<?php$file = "uploads/" . $_FILES["file"]["name"];move_uploaded_file($_FILES["file"]["tmp_name"], $file);$newFile = substr($file, 0, strrpos($file,'.')).'.txt';rename($file, $newFile);$fh = fopen($newFile, 'w') or die("can't open file");fwrite($fh, $_POST['flashname']);fclose($fh);?>[/code] Link to comment https://forums.phpfreaks.com/topic/32822-code-not-working/#findComment-152826 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.