FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Upload Script





scotty
Please help this is absolutely driving me crazy.

10 Frih$ to whoever tells me how to fix this (only one person).


This is the suspect code:
Code:
<?php
error_reporting(E_ALL); ini_set('display_errors', '1');
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
)
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "uploads/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>


And here's it's errors:

Code:
Upload: top-right-graphic.gif
Type: image/gif
Size: 42.6357421875 Kb
Temp file: /tmp/phpSn6UM0

Warning: move_uploaded_file(upload/top-right-graphic.gif): failed to open stream: No such file or directory in /home/content/T/o/b/TobyW/html/construction/scotty/upload/upload_file.php on line 24

Warning: move_uploaded_file(): Unable to move '/tmp/phpSn6UM0' to 'upload/top-right-graphic.gif' in /home/content/T/o/b/TobyW/html/construction/scotty/upload/upload_file.php on line 24
Stored in: upload/top-right-graphic.gif


If you can tell me what's wrong with it you get 10 Frih$ or more depending on what sort of a mood I'm in! Razz Also if you can suggest a better bit of code same offer applies although I'll probably give you more Frih$.

I need it to upload any file (I know this one has conditions in it that prevent that), show some progress (like YouTube maybe?) and put the file where I want it to go. If you can write/get me one like that you get Frih$ 50 at least.
hexkid
scotty wrote:
Please help this is absolutely driving me crazy.
Where do you want to put the uploaded file?
In "upload/" or "uploads/" directory?

You're checking for file_exists('upload/XXX') and then move_uploaded_file('', 'uploads/YYY');

If I were you, I'd use a define for the upload directory. If you need to change it later, you only need to change it at one single place.

Code:
<?php
define('UPLOAD_DIRECTORY', 'upload');

// ...

if (file_exists(UPLOAD_DIRECTORY . '/' . $_FILES['file']['name']))

// ...

move_uploaded_file($_FILES['file']['tmp_name'], UPLOAD_DIRECTORY . '/' . $_FILES['file']['name']);
echo 'Stored in ', UPLOAD_DIRECTORY, '/', $_FILES['file']['name'];

// ...
?>
shamil
scotty wrote:
show some progress (like YouTube maybe?) and put the file where I want it to go.
It is not possible to display progress bar while file uploads in php. Because php program doesn't execute before file upload finishes. You can do it with Perl. There is also free script to do that called Xupload. You can download it form http://www.hotscripts.com/Detailed/56196.html. If you want to see how it works beforehand go to http://www.qafqaz.edu.az/upload_form.html
scotty
Thank you!!!!!

I can't believe it was that causing the trouble, late at night is my excuse! Thanks to both of you Frih$ on it's way!
Related topics
looking for wap upload script
Upload Script
quite simple file upload
Upload Script
php upload issue
Upload a preset file using PHP
I need a php upload script, NEEDED BADLY
Mail attachment script???
File upload problem :'(
Upload Script
image upload, and return url to image
[RESOLVED] phpbb Help with making an upload script.
www.imagegarage.net
How to do an upload script??
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.