...

View Full Version : Upload Pictures to Website?



aphelion79
04-01-2007, 06:43 PM
Hello all...

I'm trying to code some PHP to upload a selected file from the user's PC to an FTP site.

Basically what I understand is this:


The User Needs to Select The File
The file then needs to be uploaded to the php server. (I.e. my computer running apache/php 5)
The PHP then needs to use that local file and upload it to the selected FTP site.
The FTP site connection needs to close
The local file on the web server (i.e. my computer running apache/php 5) needs to be deleted.
The user then needs to be aware of the success or failure of the upload.



Ok, so for #1 I've used a page called "ftp.php" that shows a very simple forum input. This then POSTs over to the upload.php file.


<body>

<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>

The problem is... when it uploads to my Apache server, the file that was selected is 100% fine. However, if I try to copy it over to the FTP site, the file size is "0". It is an empty file!

I've tried a very simple bit of code:


<?php

$conn = ftp_connect("ftp.site.here") or die("Could not connect"); // site address
ftp_login($conn,"username","password") or die("Could not login"); // login information

echo ftp_put($conn,"target.txt","source.txt",FTP_ASCII) or die("Could not Upload");


ftp_close($conn); // closes the connection


?>


Now, if I put some jibberish in the source.txt file... like "lkasdjflkjaslkj", it will upload to the FTP site and be its great self at like 20 bites of information. HOWEVER, if I try to use a .jpg image, that is say ~200K in size, the resultant file is a 0 bite empty shell.


So how I tested this was, I found a random file in my documents, sample images folder and threw it right next to the .php file I am using (same that I did with the source.txt file) that way I could eliminate file paths and just mess with the file name.


echo ftp_put($conn,"Creek.jpg","Creek.jpg",FTP_ASCII) or die("Could not Upload");

This makes a copy of "Creek.jpg" on my FTP site, but it is empty! 0 bites of data.

I also tried

echo ftp_put($conn,"Creek.jpg","Creek.jpg",FTP_BINARY) or die("Could not Upload");

and that did not work either, still an empty file.

Maybe it is

ftp_close($conn); // closes the connection
using that code too quickly before the file even gets to upload properly? I'm not entirely too sure how it works...

aphelion79
04-01-2007, 07:11 PM
I do believe it was the fact the FTP site I was using was OUT OF FREAKIN' SPACE...

So I do believe it works now, I'll let you guys know if it doesn't. :thumbsup:

Although, is there any way to upload directly to the FTP site from the user's PC?

Instead of from Their PCto the Apache/PHP5 serverto the FTP Site.
I'd like: Their PC to the FTP Site is that possible?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum