Rigo Posted March 12, 2009 Share Posted March 12, 2009 Hi everyone. I'm pretty new to php, and I figured i would start by learning simple and useful scripts. I found this upload script in a tutorial online, but it doesn't seem to work. What's wrong? <?php //set where you want to store files //in this example we keep file in folder upload //$HTTP_POST_FILES['ufile']['name']; = upload file name //for example upload file name cartoon.gif . $path will be upload/cartoon.gif GLOBAL $HTTP_POST_FILES; $path= "upload/".$HTTP_POST_FILES['ufile']['name']; if($ufile != null) //this line was at first if($ufile != none), but i got the error: undefined variable 'none' { if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)) { echo "Successful<BR/>"; //$HTTP_POST_FILES['ufile']['name'] = file name //$HTTP_POST_FILES['ufile']['size'] = file size //$HTTP_POST_FILES['ufile']['type'] = type of file echo "File Name :".$HTTP_POST_FILES['ufile']['name']."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>"; echo "<img src=\"$path\" width=\"150\" height=\"150\">"; } else { echo "Error"; Now when I run the code, i simply get "Error". This is the code that retrieves and send the variables to the upload script. <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form action="upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td><strong>Single File Upload </strong></td> </tr> <tr> <td>Select file <input name="ufile" type="file" id="ufile" size="50" /></td> </tr> <tr> <td align="center"><input type="submit" name="Submit" value="Upload" /></td> </tr> </table> </td> </form> </tr> </table> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 12, 2009 Share Posted March 12, 2009 $HTTP_POST_FILES were depricicated long ago, turned off by default in php5, and completely removed in php6. Use $_FILES instead. The GLOBAL keyword only has meaning when used inside of a function definition, so GLOBAL $HTTP_POST_FILES; has absolutely no purpose in the code. Who ever wrote that code did not know what he was doing. The variable $ufile is not being set by the code and a variable by the name would have never been set by php from the form (except possibly if register_globals are on) in all versions of php. You need to find a better and more up to date tutorial. Quote Link to comment Share on other sites More sharing options...
Rigo Posted March 12, 2009 Author Share Posted March 12, 2009 Okay, thanks 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.