Link to home
Start Free TrialLog in
Avatar of nobodynowherenothing
nobodynowherenothing

asked on

Cannot upload file with php!

Hi guys,

Write so i have a linux server - its running Centos 5.X with apache2! No firewalls as long as im aware of ... However i cannot upload ANY files to the server .. yes i am aware of the file limits in the php.ini but i cannot even upload 1k files with simplest example such as the one here :

http://www.developertutorials.com/tutorials/php/upload-files-php-050620/page1.html

The folder is created, it is 777 but still nothing!

What am i doing wrong?
Avatar of nobodynowherenothing
nobodynowherenothing

ASKER

By the way guys, Yes uploading files is on in php.ini ... and i have restarted the web server after enabaling it ..
Avatar of Joe Wu
Are you sure you have modified the right php.ini? Sometimes there can be multiple php.ini's.

Also does the script output any error at all?

Let me know how you go.
try this

<form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="2048000">
File: <input name="userfile" type="file" /><br />
<input type="submit" value="Upload" />
</form>

<?php
if (@is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
copy($_FILES["userfile"]["tmp_name"], "images/" . $_FILES["userfile"]["name"]);
echo "<p>File uploaded successfully.</p>";
}
?>

Note: this will move the file to the folder images ... if it does not exist either create it or change the script to the directory of your liking
Hello,

@ nizsmo:

Right yeah i did :

dns28:/var/www/virtual/shababi.net/htdocs# locate php.ini
/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini


And as you can see there is only 2 files and i maked sure in both php upload is on and restarted the web server ..

Been working on this since the morning .. really out of ideas ... Also i do not get any errors ...

@steelseth12

Ok i tried that .. the folder is created permission is 777 when i select a file and press upload .. the page reloads and comes back to the form so from my underestanding

if (@is_uploaded_file($_FILES["userfile"]["tmp_name"])) {

It is not set so it displayes the form again ...

Thanks for responses
it is supposed to display the form again ....  and under the form a notice "File uploaded successfully".
Ok guys got more information so i did :

print_r($_files);

and  now i get:

Array ( [userfile] => Array ( [name] => CV.docx [type] => [tmp_name] => [error] => 6 [size] => 0 ) )

So the file has been uploadded right?

@steelseth12:

Yeah but no notice .. and as i check in the folder no file ...

hmm
ASKER CERTIFIED SOLUTION
Avatar of steelseth12
steelseth12
Flag of Cyprus image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@steelseth12:

Your awsome thank you! Went into php.ini and i setup a temp folder and its working now!

Wow such a reliefe .. Thank you
Glad i could help :)