shergold Posted July 15, 2009 Share Posted July 15, 2009 Hey, can anyone please help me with the following code, it just outputs a blank page each time i execute the page. <?php include("config.inc.php"); session_start(); if (!isset($_SESSION['user'])){ header("location: login.php"); exit(); } //filepath $filename = $_FILES['file']['name']; $code = rand(5,5); $newname = $filename . $code; $link = "<a href=\"localhost/image.php?loc=$newname\""; $targetpath = "/imageup"; $targetpath = $targetpath . basename($newname); //file restrictions if ( $_FILES['file']['type'] == "image/jpg" || $_FILES['file']['type'] == "image/gif" || $_FILES['file']['type'] == "image/jpeg" && $_FILES['file']['size'] < 1048576 ) { if($_FILES['file']['error'] > 1) { exit ("<center>There has been an error uploading your file:" . $_FILES['file']['error'] . "</center><br />"); } elseif (move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$targetpath)) { echo "Your file has been succesfully uploaded <br />"; echo "<div class=\"upload_info\" align=\"center\">"; echo "<center>File uploaded: " . $_FILES['file']['name'] . "<br />"; echo "File type: " . $_FILES['file']['type']; echo "File size: " . $_FILES['file']['size']; echo "Storage location: " . "<a href=\"localhost/image.php?loc=" . uniqid() . "\"</a>"; echo "expiry date: "; echo "</div>"; } } else echo "<center><b>Invalid file</b></center>"; ?> Thanks, shergold. Quote Link to comment https://forums.phpfreaks.com/topic/166046-solved-file-upload/ Share on other sites More sharing options...
shergold Posted July 15, 2009 Author Share Posted July 15, 2009 Bump. Quote Link to comment https://forums.phpfreaks.com/topic/166046-solved-file-upload/#findComment-875685 Share on other sites More sharing options...
shergold Posted July 15, 2009 Author Share Posted July 15, 2009 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/166046-solved-file-upload/#findComment-875708 Share on other sites More sharing options...
shergold Posted July 15, 2009 Author Share Posted July 15, 2009 bump. Quote Link to comment https://forums.phpfreaks.com/topic/166046-solved-file-upload/#findComment-875729 Share on other sites More sharing options...
shergold Posted July 15, 2009 Author Share Posted July 15, 2009 Please help, i just cant see the errors in it, its getting really frustrating. Quote Link to comment https://forums.phpfreaks.com/topic/166046-solved-file-upload/#findComment-875744 Share on other sites More sharing options...
Bricktop Posted July 15, 2009 Share Posted July 15, 2009 Are you sure you want: elseif (move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$targetpath)) { echo "Your file has been succesfully uploaded <br />"; I would try: else { move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$targetpath)); echo "Your file has been succesfully uploaded <br />"; Also, your final else statement is missing the brackets - change it to: else { echo "<center><b>Invalid file</b></center>"; } Quote Link to comment https://forums.phpfreaks.com/topic/166046-solved-file-upload/#findComment-875762 Share on other sites More sharing options...
shergold Posted July 15, 2009 Author Share Posted July 15, 2009 i just fixed it before you posted, yeah it was the elseif, also you dont need curly bracers if its only one line, curly bracers are only needed when you are executing multiple lines of code. Thanks, shergold. Quote Link to comment https://forums.phpfreaks.com/topic/166046-solved-file-upload/#findComment-875780 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.