Jump to content

failed to open stream: No such file or directory


travelkind

Recommended Posts

I have written this nice little script that allows me to be able to upload a file to a server but I am getting an error.  Here is the error:

 

Notice: Undefined index: name1 in /home/content/d/l/a/dlanden/html/beer/do_upload.php on line 6

 

Warning: copy(/html/beer/uploads/) [function.copy]: failed to open stream: No such file or directory in /home/content/d/l/a/dlanden/html/beer/do_upload.php on line 6

Couldn't copy the file.

 

Here is my code:

 

<?

 

error_reporting(E_ALL);

if ($_FILES['img1'] != "") {

 

copy($_FILES['img1']['tmp_name'], "/html/beer/uploads/".$_FILES['img1']['name1'])         

or die("Couldn't copy the file.");

 

} else {

 

    die("No input file specified");

 

}

 

?>

<HTML>

<HEAD>

<TILE>Successful File Upload</TITLE>

</HEAD>

<BODY>

<H1>Success!</H1>

 

<P>You sent: <? echo $_FILES['img1']['name']; ?>,

a <? echo $_FILES['img1']['size']; ?> byte file with

a mime type of <? echo $_FILES['img1']['type']; ?>.</P>

 

</BODY>

</HTML>

 

I am a newbie and any advice on this would be much appreciated!

Link to comment
Share on other sites

Okay I changed the copy to move_uploaded_file and changed name1 to name but got the following error:

 

Warning: move_uploaded_file(/html/beer/uploads/4_cats_101.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/content/d/l/a/dlanden/html/beer/do_upload.php on line 6

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpqPEPat' to '/html/beer/uploads/4_cats_101.jpg' in /home/content/d/l/a/dlanden/html/beer/do_upload.php on line 6

Couldn't copy the file.

 

Here is my updated code:

<?

 

error_reporting(E_ALL);

if ($_FILES['img1'] != "") {

 

move_uploaded_file($_FILES['img1']['tmp_name'], "/html/beer/uploads/".$_FILES['img1']['name'])         

or die("Couldn't copy the file.");

 

} else {

 

Any ideas?

 

 

Link to comment
Share on other sites

you have write permissions on that folder?

 

try this:

 

<?php
move_uploaded_file($_FILES['img1']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . 'html/beer/uploads/' . $_FILES['img1']['name']);
?>

 

EDIT: adjust the path/to/file as necessary to make sure it's correct.  $_SERVER['DOCUMENT_ROOT'] brings you up to your public directory, in your case that's /html/ maybe?

 

if that's the case, this might work:

 

<?php
move_uploaded_file($_FILES['img1']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . 'beer/uploads/' . $_FILES['img1']['name']);
?>

 

you can always check this value and tons of others by creating a phpinfo file:

 

phpinfo.php

<?php phpinfo(); ?>

Link to comment
Share on other sites

Does the folder /html/beer/uploads/ exist and does the web server have write permissions to it? Do you not, instead, want to be saving the file to the /home/content/d/l/a/dlanden/html/beer/uploads/ folder?

 

Try

 

move_uploaded_file($_FILES['img1']['tmp_name'], dirname(__FILE__).'/uploads/'.$_FILES['img1']['name'])

 

Edit: or what mrMarcus said.

Link to comment
Share on other sites

Okay it works!!!  Thank you very much for your help.  Here is the code that I ended up using:

 

<?

 

error_reporting(E_ALL);

if ($_FILES['img1'] != "") {

move_uploaded_file($_FILES['img1']['tmp_name'], dirname(__FILE__).'/uploads/'.$_FILES['img1']['name'])     

or die("Couldn't copy the file.");

 

}

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.