Jump to content

Why? Function.move-Uploaded-File - Failed To Open Stream: No Such File Or Directory


Recommended Posts

The following error messages

 

1. [function.move-uploaded-file]: failed to open stream: No such file or directory

 

2. Unable to move '/tmp/coded file name' to .... [directory]

 

result from the following code.

 


<?php

//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['image']['name']);

//This gets all the other information from the form
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$email=$_POST['email'];
$image=($_FILES['image']['name']);

// Connects to your Database
include "connect.php";

//Writes the information to the database
mysql_query (

"INSERT INTO `database`(`first_name`,`last_name`,`email`,`image`,) VALUES ('$first_name','$last_name','$email','$image',)" );

//Writes the photo to the server
if(move_uploaded_file($_FILES['image']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>

 

Any help would be GREATLY apprecaited!!

Your directory is images/, no images. basename( $_FILES['image']['name']) .

 

EDIT: just delete this line - $target = $target . basename( $_FILES['image']['name']);

Edited by jazzman1

I deleted the line, but I still received an error:

 

failed to open stream: Is a directory in .... [site directory]

 

What is "Is" as directory? I did a search for Is and for directory in case I had some typos. Not finding anything.

Edited by sildona

ls is a Unix command.

I don't see any errors in this script. What permissions do you have to the image directory?

 

EDIT: Also, check whether your html form has enctype=multipart/form-data.

Edited by jazzman1

Try,

<?php
//This is the directory where images will be saved
$target = "images";
//This gets all the other information from the form
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$email=$_POST['email'];
$img_name=basename(($_FILES['image']['name']));
$tmp_name = $_FILES["image"]["tmp_name"];
// Connects to your Database
include "connect.php";
//Writes the information to the database
mysql_query (
"INSERT INTO `database`(`first_name`,`last_name`,`email`,`image`) VALUES ('$first_name','$last_name','$email','$img_name')" );
//Writes the photo to the server
if(move_uploaded_file($tmp_name, $target.'/'.$img_name))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>

 

EDIT: You also had two errors in your sql string (two extra commas) I removed them...

Edited by jazzman1
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.