View Full Version : Uploading issue with different server

03-01-2007, 03:14 PM
Good morning all. I have been working on a file/newsletter admin system and it runs flawlessly on my local machine (MAMP on Mac). However, when i put it online to the host that I plan on using, it doesnt want to upload any file i throw at it. It just errors out with my error message.

Here is a snip of my code that deals with the file upload:

//assign post data
$title = $_POST['newstitle'];
$code = $_POST['newscode'];
$booklets = implode(',',$_POST['newsbooklets']);
$sections = implode(',',$_POST['sections']);
$date = date("F j, Y");
$uploadDir = 'documents/newsletters/';

//upload file routine
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$filePath = $uploadDir . $fileName;

$result = move_uploaded_file($tmpName, $filePath);

if (!$result)
echo "Error uploading file.";

$fileName = addslashes($fileName);
$filePath = addslashes($filePath);

$result seems to be empty since that is where it is erroring out. I kind of have a feeling it might be some type of configuration of my host (1and1.com). If anyone could possibly assist me with this, i'd greatly appreciate it.


03-01-2007, 03:19 PM
Either check your server log for errors or put the following two lines in after your first opening <?php tag -

ini_set ("display_errors", "1");

03-01-2007, 03:37 PM
Thanks for the idea of checking out the logs, who would of thought? It has been a rather hazy morning thus far.. Anyways, onto what I found.

I used a method for creating error log files suggested by 1and1, since I do not have direct access to the raw logs. Here is the error it outputs.

"01 Mar 2007 10:28:58","/homepages/6/d194824923/htdocs/docadmin/adddata.php:
31","(Warning) move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move '/tmp/phpzE7rwN' to 'documents/newsletters/test.txt'"
Obviously it is having trouble either locating the temp file, or moving it. Anyone familiar with how 1and1 handles file uploads or am I just missing something here? Thanks

03-01-2007, 03:42 PM
Perhaps PHP does not have access to the temporary folder, or the folder it is moving to.

Did you check to see whether the temporary file exists using file_exists()?

03-01-2007, 03:52 PM
It seems to exist:

File exists: /tmp/phpoOYwET

It is still producing the same error:

"(Warning) move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move '/tmp/phpoOYwET' to 'documents/newsletters/test.txt'"

03-01-2007, 04:03 PM
Fixed it. I set the upload directory relative to the document root

$uploadDir = $_SERVER['DOCUMENT_ROOT'] . "documents/newsletters/";

instead of just:

$uploadDir = 'documents/newsletters/';