I try to upload an image to a directory on localhost.
Here is the part in my php file, which causes the error:
if (move_uploaded_file($tmp_name, "/Users/sandro/Documents/bildgalerie/uploads")) {
echo "The file " . basename($filename) . " has been uploaded";
} else {
echo "error";
}
If I load the page, I get the following:
Warning: move_uploaded_file(): Unable to move '/private/var/folders/np/sln14hvn3tsbzc4kpjjtp17c0000gn/T/phppJbFJK' to '/Users/sandro/Documents/bildgalerie/uploads' in /Users/sandro/Documents/bildgalerie/control/upload.php on line 31
Related
I'm trying to extract zip files from a folder into a subfolder. The error I'm recieving is:
Warning: ZipArchive::extractTo(XXXX): failed to open stream: Permission denied in /var/www/html/update_alerts2.php on line 97
extracted
Code :
public function extractFiles($inputDir,$outputDir) {
$files_to_extract = $this->getFiles($inputDir);
$zip = new ZipArchive();
foreach ($files_to_extract as $file) {
echo $file;
$res = $zip->open($inputDir . $file);
if ($res) {
$zip->extractTo($outputDir);
$zip->deleteName($inputDir . $file);
$zip->close();
} else {
echo 'failed, code:' . $res;
}
}
}
I've tried setting permissions to 777 but I still get the error. What are the possible ways I can fix this issue (I'm using centos7 and apache) ?
I just wanna ask if its possible to make directory and store the uploaded file in it to a shared folder from another pc using mkdir and move_uploaded_file. I tried doing it locally it works fine but when i try this code
if($_REQUEST['submit']){
$app_name = $_POST['name'];
$desc = $_POST['description'];
$file_url = "192.168.3.34/testupload/files/$app_name/" . $_FILES["file"]["name"];
$photo_loc = "192.168.3.34/testupload/images/$app_name/" . $_FILES["photo"]["name"];
$select = $_POST['select'];
$date = date('m/d/y h:i:s A');
mkdir("192.168.3.34/testupload/files/$app_name/");
mkdir("192.168.3.34/testupload/images/$app_name/");
/* some codes here that is working */
if($file != "" ){
if (file_exists("..192.168.3.34/testupload/files/$app_name/" . $_FILES["file"]["name"]) && file_exists("..192.168.3.34/testupload/images/$app_name/" . $_FILES["photo"]["name"])) {
die("File Exists");
}
move_uploaded_file($_FILES["file"]["tmp_name"],
"192.168.3.34/testupload/files/$app_name/" . $_FILES["file"]["name"]);
if($photo_url != "") {
move_uploaded_file($_FILES["photo"]["tmp_name"],
"192.168.3.34/testupload/images/$app_name/" . $_FILES["photo"]["name"]);
}
$name = escape($_REQUEST['name']);
$description = escape($_REQUEST['description']);
//$query = "INSERT into files (name, description,file_name,photo_url,date_uploaded) values ('{$name}', '{$description}','{$file}', '{$photo_url}', now() )";
//mysql_query($query) or die("Error in Query" . mysql_error());
//commit();
//redirect("manage.php");
$file_loc = "192.168.3.34/testupload/files/$app_name/" . $_FILES["file"]["name"];
$photo_loc = "192.168.3.34/testupload/images/$app_name/" . $_FILES["photo"]["name"];
}
}else{
set_error("File not Found");
//redirect('manage.php');
}
i tried to change the "/" in "\" and still getting this error
Warning: mkdir() [function.mkdir]: No such file or directory in
C:\xampp\htdocs\atts_update\upload.php on line 12
Warning: mkdir() [function.mkdir]: No such file or directory in
C:\xampp\htdocs\atts_update\upload.php on line 13
Warning:
move_uploaded_file(192.168.3.34/testupload/files/1111111111111/sss.txt)
[function.move-uploaded-file]: failed to open stream: No such file or
directory in C:\xampp\htdocs\atts_update\upload.php on line 71
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to
move 'C:\xampp\tmp\php610B.tmp' to
'192.168.3.34/testupload/files/1111111111111/sss.txt' in
C:\xampp\htdocs\atts_update\upload.php on line 71
Warning:
move_uploaded_file(192.168.3.34/testupload/images/1111111111111/Picture-in-a-picture4aaa.jpg) [function.move-uploaded-file]: failed to open stream: No such file or
directory in C:\xampp\htdocs\atts_update\upload.php on line 76
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to
move 'C:\xampp\tmp\php611C.tmp' to
'192.168.3.34/testupload/images/1111111111111/Picture-in-a-picture4aaa.jpg' in C:\xampp\htdocs\atts_update\upload.php on line 76
I am trying to upload files to a server using PHP move_uploaded_file and I am getting the following error:
Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in /Users/Rick/Sites/upload/upload.php on line 7
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/Applications/XAMPP/xamppfiles/temp/phpDlCZUd' to '/Users/Rick/Sites/upload/uploads/richardgregson' in /Users/Rick/Sites/upload/upload.php on line 7
Below is my code, nothing complicated.
if($_POST["upload"]){
$target_path = "/Users/Rick/Sites/upload/uploads/" . $_POST["name"];
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)){
echo "<div class='success'>The file " . "<span class='filename'>" . basename( $_FILES['uploadedfile']['name']) . "</span>" . " has been uploaded</div>";
} else {
echo "<div class='error'>There was an error uploading the file, please try again!</div>";
}
}
The permissions on the folder it is writing to are correct. I dont understand the error "cannot be a directory as the argument is where we are moving the file to so it has to be a directory.."
Thanks
Rick
The error is telling you what's wrong - $target_path (/Users/Rick/Sites/upload/uploads/richardgregson) is a directory
Try adding an extension.
$extension=end(explode('.', $_FILES["uploadedfile"]["name"]));
$target_path = "/Users/Rick/Sites/upload/uploads/" . $_POST["name"] . '.' . $extension;
Or perhaps your putting the file into a folder
$target_path = "/Users/Rick/Sites/upload/uploads/" . $_POST["name"] . '/' . $_FILES["uploadedfile"]["name"];
Note: you should not trust the user to upload only the files you want and you should sanitise $_POST["name"], all too easy to make that '../../' and post a PHP file.
I am trying to make a simple uploading application from a web page:localhost/test.html. I am getting these errors:
Warning: move_uploaded_file(test/Blue hills.jpg): failed to open stream:
No such file or directory in C:\wamp\www\test.html on line 11
and
Warning: move_uploaded_file(): Unable to move 'C:\wamp\tmp\php376.tmp'
to 'test/Blue hills.jpg' in C:\wamp\www\test.html on line 11
Here is my code
<html>
<form enctype="multipart/form-data" action="test.html" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>
<html>
<?php
$target = "test/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
} else {
echo "Uploading Error.";
}
Probably the directory test doesn't exist. Add these lines to your code.
if (file_exists('test/')) echo 'Ok it wasn\'t that';
else echo 'Um, create a directory called test here: '.dirname(__FILE__);
Ensure that the a test/ directory exists in the directory where your script is located, then you can use
$out = dirname(__FILE__) . '/' . $_FILES['uploaded']['name'];
move_uploaded_file($_FILES['uploaded']['tmp_name'], $out);
Change directory permissions (CHMOD) to 777 via your FTP client (read,write,execute for owner,group,public).
I have the following code below, I cannot get why it's not working.
$server=("ftp.blah.com");
$connect=ftp_connect($server);
$dest='/';
$login_result=ftp_login($connect,"blah#blah.com","lol");
if(!($login_result)||!($connect))
{
$error;
} else {
echo "success";
}
$file= 'Tiny-' . $time. '.txt';
$upload=ftp_put($connect,$dest,$file,FTP_ASCII);
if (!$upload)
{
echo "failed to upload";
} else{
echo "successfully uploaded";
}
ftp_close($connect);
When i run the code, i get the error "Warning: ftp_put(Tiny-201201070758.txt): failed to open stream: No such file or directory
I have made the destination folder of the ftp write and read accessible.
I have also tried to include the full path of the text file by:
$file= 'C:\xampp\htdocs\Tiny-' . $time. '.txt'
or
$file= 'C:\\xampp\\htdocs\\Tiny-' . $time. '.txt'
I also tried using FTP_Binary instead of ASCII, still no luck.
nothing works.
Have you got url_fopen active on your server? Check with phpinfo().