PHP: move_uploaded_file() failed to open stream: No such file or directory
A simple way to keep track of the path is just to define the absolute path in your index.php
define ('SITE_ROOT', realpath(dirname(__FILE__)));
Then just use it like:move_uploaded_file($_FILES['file']['tmp_name'], SITE_ROOT.'/static/images/slides/1/1.jpg');
move_uploaded_file() failed to open stream: no such file or directory
you do not need to put the full directory to the file. try to remove /public_html/flashsale/
from your link and see if that will work.
In addition, the file does not need to have 777 permission, I myself upload files to folders with 755 permissions.
also, you can use getcwd();
in the directory your aiming to. the function will give you the directory that you need to use for moving your file. source
Move_upload_file() is failed to open stream and Unable to move file
You have to verify some points as per below.
1) Ensure your form have enctype="multipart/form-data"
2) Please check your root directory you have to created folder "manufacturer"
Now I expect following files you have
form.php File
<form name="fileUpload" method="post" id="fileUpload" enctype="multipart/form-data" action="success.php">
<input type="text" name="image_title">
<input type="file" name="photo">
<input type="submit" name="add_code" value="Submit">
</form>
success.php File<?php
if(isset($_POST['add_code'])){
if (($_FILES['photo']['name']!="")){
// Where the file is going to be stored
$target_dir = "manufacturer/";
$file = $_FILES['photo']['name'];
$path = pathinfo($file);
$filename = $path['filename'];
$ext = $path['extension'];
$temp_name = $_FILES['photo']['tmp_name'];
$path_filename_ext = $target_dir.$filename.".".$ext;
// Check if file already exists
if (file_exists($path_filename_ext)) {
echo "Sorry, file already exists.";
}else{
move_uploaded_file($temp_name,$path_filename_ext);
echo "Congratulations! File Uploaded Successfully.";
}
}
$ititle=$_POST['image_title'];
$c_=mysqli_query($connection,"INSERT INTO `manufacturer`(`mname`, `mimg`) VALUES ('$ititle','$path_filename_ext')");
//$check_user_data=mysqli_fetch_array($check_user_);
if($c=true){
echo '1';
}
}
?>
Please try with above listed code and i hope it works. move_uploaded_file(...): failed to open stream: No such file or directory
In your Config file or some common file define your path as below
define('DOCROOT', $_SERVER['DOCUMENT_ROOT'].'<YOUR PROJECT DIRECTORY>/');
Include this common php in all your class file.
Then
$destino= DOCROOT.'Perf_Masc/'.$img; // HERE DOCROOT is defined in config.
Image upload error failed to open stream: No such file or directory
Change this line :
$target_file = 'images/' . $uploadFileName;
To:
$target_file = 'images/' . basename( $_FILES["imageToUpload"]["name"]);
Also make sure that you have the images
folder.
php file upload error warning move_uploaded_file failed to open stream permission denied in
I have tried the same code and it works for me. I have made some changes for you.
<form method="POST" enctype="multipart/form-data">
<label for="">Upload Your Cv</label><input type="file" name="file">
<input type="submit" name="upload" value="upload">
</form>
After that you don't need to redirect the page; instead you can use this, below the </form>
if(isset($_REQUEST["upload"]))
{
if (isset($_FILES['file'])) {
$file = $_FILES['file'];
// print_r($file); just checking File properties
// File Properties
$file_name = $file['name'];
$file_tmp = $file['tmp_name'];
$file_size = $file['size'];
$file_error = $file['error'];
// Working With File Extension
$file_ext = explode('.', $file_name);
$file_fname = explode('.', $file_name);
$file_fname = strtolower(current($file_fname));
$file_ext = strtolower(end($file_ext));
$allowed = array('txt','pdf','doc','ods');
if (in_array($file_ext,$allowed)) {
//print_r($_FILES);
if ($file_error === 0) {
if ($file_size <= 5000000) {
$file_name_new = $file_fname . uniqid('',true) . '.' . $file_ext;
$file_name_new = uniqid('',true) . '.' . $file_ext;
$file_destination = 'upload/' . $file_name_new;
// echo $file_destination;
if (move_uploaded_file($file_tmp, $file_destination)) {
echo "Cv uploaded";
}
else
{
echo "some error in uploading file".mysql_error();
}
//
}
else
{
echo "size must bne less then 5MB";
}
}
}
else
{
echo "invalid file";
}
}
}
Note that the upload folder must be in the same directory as where you store the file. Warning: move_uploaded_file() failed to open stream
First:
You have a space here mkdir('/Trade/upload/ '.$jname);
. Suppose you should have mkdir('/Trade/upload/'.$jname);
(same for is_dir)
Second:
Ensure that you can write into Trade/upload
directory.
Third (and I suppose that is the real problem):
It looks like you are trying to upload into a directory with full path:/home/my_username/public_html/Trade/upload/
, but your code will try to create a directory with full path:/Trade/upload/
.
You need to change
if (!is_dir('/Trade/upload/ '.$jname)) {
mkdir('/Trade/upload/ '.$jname); // line 63
}
to if (!is_dir('upload/'.$jname)) {
mkdir('upload/'.$jname); // line 63 (or maybe there should be Trade/upload, but suppose current working dir will be /home/my_username/public_html/Trade, so only upload/)
}
Another option is to force mkdir
to create directories recursively: mkdir('/Trade/upload/'.$jname, 0755, true);
But in that case, files will be uploaded into /Trade/upload/...
instead of /home/my_username/public_html/Trade/upload/...
Related Topics
How to Make an Array of Times with Half Hour Intervals
Get Folders with PHP Glob - Unlimited Levels Deep
Speeding Up Large Numbers of MySQL Updates and Inserts
Laravel 4 - Including a "Partial" View Within a View (Without Using Blade Template)
Regular Expression for French Characters
Using PHP & Curl to Login to My Websites Form
Error Starting Userland Proxy: Listen Tcp 0.0.0.0:3306: Bind: Address Already in Use
Difference Between Directoryiterator and Filesystemiterator
Laravel - Validate File Size When PHP Max Upload Size Limit Is Exceeded
Use of Undefined Constant Mcrypt_Rijndael_128 - Assumed 'Mcrypt_Rijndael_128'
PHP MySQL Query Where X = $Variable
Check If the Current Date Is Between Two Dates + MySQL Select Query
Can One Modify the Templates Created by Artisan Migrate Command