Jump to content

Problems uploading files


charlie_d

Recommended Posts

Hi, I am new to PHP and am having major problems with a basic upload script as follows:

 

Using php 5.2.5 and IIS on my local machine.

Am trying to run a very basic upload script

 

print_r($_FILES); gives me all the correct details of the uploaded file and [error] => 0

but when I check the tmp upload folder as specified in php.ini and as returned by print_r($_FILES); , there is no .tmp file.

 

Also move_uploaded_file always returns false.

 

What am I doing wrong

Link to comment
Share on other sites

Thanks discomatt but;

 

Images folder exists and I have also tried using different folders created sepecially to test this, and I have used both relative and absolute paths and with slashes going both ways.

 

Still getting nowhere

 

Due to loss of posts - here is problem again in full:

 

I am using php 5.2.5 and IIS 5.1 on MS Windows Pro with SP2 installed

 

I am attempting a simple file upoad with first page:

 

 

<form enctype="multipart/form-data" action="test_uploadck.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="75000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

 

and test_uploadck.php:

 

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
print "<pre>";

$target_path = 'Images/';
$target_path = $target_path . basename( $_FILES['userfile']['name']); 

if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['userfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";
?> 

 

I get the following errors:

 

Warning:  move_uploaded_file(Images/AL19307A.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\Inetpub\wwwroot\estateagent1\test_uploadck.php on line 18

Warning:  move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\PHP\tmp\php43.tmp' to 'Images/AL19307A.jpg' in C:\Inetpub\wwwroot\estateagent1\test_uploadck.php on line 18

 

I have checked the standard pitfalls as follows:

 

a) the file being uploaded was not too big (only 22K) and did not exceed either MAX_FILE_SIZE (750000) in the script or post_max_size and upload_max_filesize (both 8M) in php.ini.

b) the folder I was moving the uploaded file to exists and has all permissions enabled in IIS

c) There were no normal input fields in the upload form

 

Where am I going wrong?

 

 

Link to comment
Share on other sites

Try using the fopen function to read the temp file. By doing this we would know that;  is the file getting saved in temp directory? if yes, you can fread the file till filesize extent and fwrite to your destination.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.