FlyingIsFun1217 Posted April 20, 2008 Share Posted April 20, 2008 Hey! Need more code help. I can't seem to upload anything to my server (would be the ftp_put function if anything). Here's what I have: <?php include("header.php"); ?> <form action="uploadImage.php" method="post"/> <center> <p> <b>Image to Upload:</b> <input type="file" name="imageLocalLoc" style="color: #383838; background-color: #46C74A;"/> </p> <br> <p> <b>Image Name (No Extension Needed):</b> <input type="text" name="imageName" style="color: #383838; background-color: #46C74A;"/> </p> </center> <center> <input type="submit" value="Upload Image!"> </center> </form> <?php include("footer.php"); ?> and uploadImage.php: <?php $ftp_server = "flyingisfun1217.freeweb7.com"; $ftp_user_name = "flyingisfun1217"; $ftp_user_pass = "my_ftp_password_here"; $pictureName = $_POST['passwrd']; $ftpName = $_POST['imageName']; $ext = substr($pictureName, strrpos($fileName, '.') + 1); $serverConnection = ftp_connect($ftp_server); $login_result = ftp_login($serverConnection, $ftp_user_name, $ftp_user_pass); if ((!$serverConnection) || (!$login_result)) { echo "FTP connection has <b>failed!</b>"; echo "<br>"; echo "Attempted to connect to ".$ftp_server." for user ".$ftp_user_name; echo "<br>"; exit; } else { echo "FTP connection has <b>succeeded!</a>"; echo "<br>"; echo "Connected to ".$ftp_server.", for user ".$ftp_user_name."."; echo "<br>"; } $upload = ftp_put($serverConnection, $ftpName.".jpg", $pictureName, FTP_BINARY); if (!$upload) { echo "FTP upload of ".$ftpName.".jpg has failed!"; } else { echo "Uploaded $source_file to $ftp_server as $destination_file"; } ftp_close($serverConnection); ?> Every time I try and run it, it gives me my dreaded "FTP upload of Image.jpg has failed!". What could be wrong here? Thanks again! FlyingIsFun1217 Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 20, 2008 Share Posted April 20, 2008 Well, the ftp_put() function takes a local file, and uploads it to an ftp server. The file in question isn't local to the server, it's local to the user's machine. You don't need FTP functions for this. PHP can handle uploads itself. Take a look at the manual page: http://uk.php.net/manual/en/features.file-upload.php There's a full example of an upload form there. Quote Link to comment Share on other sites More sharing options...
FlyingIsFun1217 Posted April 21, 2008 Author Share Posted April 21, 2008 The only reason I wanted to do an FTP upload is because it seems my hosting provider has not allowed php to upload to the server. There's no way of doing an FTP upload through a remote (user's PC) machine? Seems like it would be such a trivial thing. Thanks again for your time! FlyingIsFun1217 Quote Link to comment Share on other sites More sharing options...
dezkit Posted April 21, 2008 Share Posted April 21, 2008 no way Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 Replace: <form action="uploadImage.php" method="post"/> With: <form enctype="multipart/form-data" action="uploadImage.php" method="post"/> <input type="hidden" name="MAX_FILE_SIZE" value="30000"> Fill MAX_FILE_SIZE with the appropriate value (in bytes), and try it again. Quote Link to comment Share on other sites More sharing options...
FlyingIsFun1217 Posted April 21, 2008 Author Share Posted April 21, 2008 Thanks Nice to see another 'buntu user. Visit the forums much? Maybe I'd know you... Thanks again! FlyingIsFun1217 Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 I visit the forums from time to time. Same forum ID as this one. I usually only help people out with Installs and stuff, because that's all I have time for. PHP is much more fun, anyway. =) Did my suggestion work, btw? Quote Link to comment Share on other sites More sharing options...
FlyingIsFun1217 Posted April 21, 2008 Author Share Posted April 21, 2008 Ah. I'm usually in the Development section, since I'm better with C++ Tried just adding the enctype, it resulted in the same stuff as before (an error saying that the upload failed, but connections succeeded). FlyingIsFun1217 Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 22, 2008 Share Posted April 22, 2008 None of the enctype stuff is going to help if your host isn't allowing PHP uploads. My suggestion: move host. Quote Link to comment Share on other sites More sharing options...
FlyingIsFun1217 Posted April 22, 2008 Author Share Posted April 22, 2008 Ahh, so the enctype stuff is for a normal PHP upload? I was using it with the FTP upload. Thanks! FlyingIsFun1217 Quote Link to comment Share on other sites More sharing options...
FlyingIsFun1217 Posted May 2, 2008 Author Share Posted May 2, 2008 I know it's been a while, but that didn't work upload.php: <?php include("header.php"); ?> <form enctype="multipart/form-data" action="fileUp.php" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="10485760"> <center> <input type="file" name="fileForUp"> <br> <input type="submit" value="Upload"> </center> </form> <?php include("footer.php"); ?> fileUp.php <?php $fileToUpload = $_POST['fileForUp']; $targetPath = "/".basename($_FILES['fileForUp']['name']); if(move_uploaded_file($_FILES['fileForUp']['name'])) { include("header.php"); echo '<center>'; echo 'File successfully uploaded!'; echo '<br>'; echo '<a href="javascript:history.go(-1)">Return to Upload Form</a>'; echo '</center>'; include("footer.php"); } else { include("header.php"); echo '<center>'; echo 'Unsuccessful file upload!'; echo '<br>'; echo '<a href="javascript:history.go(-1)">Return to Upload Form</a>'; echo '</center>'; include("footer.php"); } ?> Thanks again! FlyingIsFun1217 Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 2, 2008 Share Posted May 2, 2008 Your host might not physically allow file uploads to a PHP script (the script then passes it to the FTP, but it must go through the script first). Contact your host about it or switch hosts. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 2, 2008 Share Posted May 2, 2008 None of the enctype stuff is going to help if your host isn't allowing PHP uploads. My suggestion: move host. Quote Link to comment Share on other sites More sharing options...
FlyingIsFun1217 Posted May 3, 2008 Author Share Posted May 3, 2008 Well, the only reason I mention it at all now is because searching through their forums, others have been able to upload through php. I just wanted to check to make sure it was all correct before I started complaining And switching hosts would be hard. I'd need something comparable to what I've got now (free, 8 GB, 100 GB bandwidth), just with these functions allowed. FlyingIsFun1217 Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 3, 2008 Share Posted May 3, 2008 Free? =/ I'd suggest getting another host. Because you never know when a free host will go bye-bye. Quote Link to comment Share on other sites More sharing options...
FlyingIsFun1217 Posted May 3, 2008 Author Share Posted May 3, 2008 They've actually lasted quite a while, and while I can't predict the future, I can see them lasing for quite a while (they also do paid hosting). Right now though, as I've said, it has to be free. There is simply no way for me to do paid hosting yet (under 18, and parents would not want to pay for that; neither would I). Thanks again! FlyingIsFun1217 Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 3, 2008 Share Posted May 3, 2008 Oh, they also do paid hosting. Okay. =P Do they put ads on your site and stuff? =P And I pay for a site even though I'm under 18. >_> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 3, 2008 Share Posted May 3, 2008 It's possible that your host only allows PHP uploads for paying members, which might explain the forums posts. Either way, you can check if your host is allowing PHP uploads by looking at the output of phpinfo(); One of the options under PHP core is file_uploads. As for your code one thing immediately jumps out at me. The move_uploaded_file() function requires two parameters. You only give it one. See the manual for a short, simple example of a PHP file upload script. Quote Link to comment Share on other sites More sharing options...
FlyingIsFun1217 Posted May 4, 2008 Author Share Posted May 4, 2008 Ok, thanks (both of you). I'll check with the server. And fix the move... arguments And no, no ads on the site. Well, see for yourself. FlyingIsFun1217 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.