Jump to content

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


sildona

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!!

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.

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.

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.