I am trying to upload file on ftp.
here is my code
$jname= "Accounts of Biotechnology Research";
if (!is_dir('/Trade/upload/ '.$jname)) {
mkdir('/Trade/upload/ '.$jname); // line 63
}
move_uploaded_file($_FILES["submission_file"]["tmp_name"], "/Trade/upload/$jname/" . $dup_name ); // line 67
Trade is a folder inside public_html folder.
When i am uploading a file it gives me a warning like,
Warning: mkdir() [function.mkdir]: No such file or directory in /home/my_username/public_html/Trade/upload.php on line 63
Warning: move_uploaded_file(/Trade/upload/Accounts of Biotechnology Research/76164762-sm.pdf) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/my_username/public_html/Trade/upload.php on line 67
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phphZXp0O' to '/Trade/upload/Accounts of Biotechnology Research/76164762-sm.pdf' in /home/my_username/public_html/Trade/upload.php on line 67
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/...
There are two things you should be aware of based on the error messages you received. I'm guessing /Trade isn't the root path on your machine since it's clear in the error that your actual path is /home/my_username/public_html/Trade/, so the first adjustment should be
$root_path = "/home/my_username/public_html/Trade/upload/";
The second adjustment I'd suggest is that you avoid pathnames with space in them:
$jname= "Accounts of Biotechnology Research"; //could be changed to
$jname= "Accounts_of_Biotechnology_Research"; //$jname = str_replace(" ","-",$jname) OR
$jname= "Accounts-of-Biotechnology-Research"; //$jname = str_replace(" ","-",$jname)
Finally take note of the space character on the following lines, they affect you final result:
if (!is_dir('/Trade/upload/ '.$jname)) { //AND
mkdir('/Trade/upload/ '.$jname);
}
Note the [space] between upload/ '.$jname in both strings.
Related
I'm working on a file upload method. But i suddenly start to get the following error, The only thing I changed was the file name. I reverted it back, but the error still persists.
Does anyone know how to solve this?
The error message is:
Warning: move_uploaded_file(): The second argument to copy()
function cannot be a directory in
/hermes/bosnaweb14a/b1717/ipg.plantationkeyartcorn/kittyrescuetnr/docs/upload.php
on line 13
Warning: move_uploaded_file(): Unable to move '/tmp/phpJki8OC' to '/' in
/hermes/bosnaweb14a/b1717/ipg.plantationkeyartcorn/kittyrescuetnr/docs/upload.php
on line 13
Fail
my php looks like this
<?php
$file_upload="true";
$file_up_size=$_FILES['file_up'][size];
$file_destination=$REQUEST['file_type'];
$file_new_name=$REQUEST['file_name'];
$file_name=$_FILES[file_up][name];
**$add="$file_destination/$file_new_name"; // the path with the file name where the file will be stored**
if($file_upload=="true"){
if(move_uploaded_file ($_FILES[file_up][tmp_name], $add)){
echo print_r($file_new_name);
}else{echo "Fail";}
}else{
echo $msg;
}
?>
Well, since you are using superglobal array $_REQUEST incorrectly (notice the underscore in the name), your $add variable evaluates to just a slash. Which is a root directory.
Hence the errors - it is a directory after all and your script probably don't have write access to it anyway (which is a good thing).
So the scenario is, I have an ecommerce site which involves users uploading files & details, the links to the files & the text of the details is saved into a text file. All this stuff is uploaded into a temporary folder.
The payment system I have integrated is Paypal. I have Paypal send a response to the IPN. In this file, I send some emails, but I also wish to move the files into a permanent folder and thus edit the links in the text file. But I can't seem to access the files properly.
This is my error codes:
file_get_contents( ../uploads/tmp/file/*FILE NAME HERE*.doc) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No such file or directory in /home/*username here*/public_html/*name*/*dir*/ipn.php on line 103
PHP Warning: file_put_contents( ../uploads/tmp/file/*FILE NAME HERE*.doc) [<a href='function.file-put-contents'>function.file-put-contents</a>]: failed to open stream: No such file or directory in /home/*username here*/public_html/*name*/*dir*/ipn.php on line 103
PHP Warning: copy( ../uploads/tmp/file/*FILE NAME HERE*).doc) [<a href='function.copy'>function.copy</a>]: failed to open stream: No such file or directory in *link to ipn.php* on line 106
//This is my code
if ($key == 'Book File '){
$oldBookFileName = $result['Book File '];
$oldBookLink = str_replace('*BASE URL IS HERE*', '../',$oldBookFileName);
if (strpos($result['Book File '],'/tmp/') !== false) {
$newBookFileName = str_replace("/tmp/","/perm /",$oldBookFileName);
$newBookLink = str_replace('*BASE URL IS HERE*', '../',$newBookFileName);
}
//update file names in file & move files
//include ('updatefile.php');
file_put_contents($oldBookLink, str_replace($oldBookFileName, $newBookFileName, file_get_contents($oldBookLink)));
//copy/move files from tmp to perm
copy($oldBookLink, $newBookLink);
}
I've tried using the full path (www.example.com/dir/file.php) and using the relative path (../dir/file.php). Also, all the links are correct, I echo'ed them out in an email and they are correct.
Anyone know what Im doing wrong? Something totally retarded? Please help.
Thank you.
You likely have the relative path wrong. Try using realpath() to see what path PHP is actually using.
For the full path you need to use the path on the server, not the http URL. So something like /home/username/public_html/dir/filename.doc instead of www.example.com/dir/filename.doc
I have 3 php pages where details is supposed to be inserted to db in final php.. I am geetting these warnings below however data is inserted. I know these warning can be turned of by error reporting but doesnt look good to me go for that..
Warning: copy(): The first argument to copy() function cannot be a directory in /home/opterfhb/public_html/quest4home.com/search/add_edit_property_finish.php on line 301
Warning: unlink(tmp_imgs/tmp_1011/..): Is a directory in /home/opterfhb/public_html/quest4home.com/search/add_edit_property_finish.php on line 302
Warning: copy(): The first argument to copy() function cannot be a directory in /home/opterfhb/public_html/quest4home.com/search/add_edit_property_finish.php on line 301
Warning: unlink(tmp_imgs/tmp_1011/.): Is a directory in /home/opterfhb/public_html/quest4home.com/search/add_edit_property_finish.php on line 302
I think I have defined it wrong way.. seeking help..
I am getting error on this section:
// Moveing temp images to property directory
if ($handle = opendir('tmp_imgs/tmp_'.$property_id)) {
while (false !== ($file = readdir($handle)))
{
//$file_ext = strtolower(substr($file, strrpos($file, '.') + 1));
copy('tmp_imgs/tmp_'.$property_id.'/'.$file, 'property_images/img_'.$property_id.'/'.$file);
unlink('tmp_imgs/tmp_'.$property_id.'/'.$file);
}
closedir($handle);
}
The error is clear: you cannot use that function to copy directories. However, you may not be aware that you're even trying to do this in the first place.
There are magical "files" in each directory which are themselves directories (. and ..), so if you're iterating over a directory and copying everything in it, you need to explicitly skip those two.
if(!is_dir($dir_path))
{
$mk_dir=mkdir($dir_path, 0777);
$ch_mod=chmod($dir_path, 0777);
}
In the above code I am getting errors like below:
Warning: mkdir() [function.mkdir0]: No such file or directory in E:\salaahakardb\New Folder\xampp\htdocs\extramarks2\jnrcontent\fillblanks\form_vars.php on line 66
Warning: chmod() [function.chmod0]: No such file or directory in E:\salaahakardb\New Folder\xampp\htdocs\extramarks2\jnrcontent\fillblanks\form_vars.php on line 67
Please explain
The parent directory of the directory you're trying to create probably doesn't exist.
One way could be to create it recursively:
mkdir($dir_path, 0777, true);
Check http://php.net/manual/en/function.mkdir.php for further info.
Also you can get rid of that chmod() since you are already setting permissions while mkdir()'ing.
is_dir function returns false, if passed parameter is file - it's your situation.
try file_exists function
I want to create File that have Full permission dynamically, that means every change for ID of session create new file .
Unfortunately I faced some problem .
Warning: fopen(test.txt) [function.fopen]: failed to open stream: Permission denied in /home/teamroom/public_html/1/3.php on line 2
Warning: fwrite(): supplied argument is not a valid stream resource in /home/teamroom/public_html/1/3.php on line 3
Warning: fclose(): supplied argument is not a valid stream resource in /home/teamroom/public_html/1/3.php on line 4
code :
<?php
session();
$member_Id=$_SESSION['user_id'];
if (isset($member_Id)){
$file = fopen("test.txt","x+");
fwrite($file,"test");
fclose($file);
}
?>
can you help me ?
or can you tell another way to do this idea ?
It would appear that the process PHP is running as (often the web server, e.g. www-data) does not have write permissions for the folder you're trying to create the file in
(e.g. /home/teamroom/public_html/1/).
You also should be doing error checking on the fopen() call. Then there's the security assect to think of.
you have no permissions to access directory. Use php-function chmod ("/somedir/somefile", 755); or change directory permissions by ftp-client.
And why are you trying to open file with x+ if you need only writing:
Modes:
r - Reading only, beginning of file
r+ - Reading and writing, beginning of file
w - Writing only, beginning of file
w+ - Writing and reading, beginning of file
a - Writing only, end of file
a+ - Writing and reading, end of file
x - Create and open for writing only, beginning of file
x+ - Create and open for reading and writing, beginning of file
If the file does not exist and you use w, w+, a or a+ it will attempt to create the file.
I think you can use w+ or a+
And for your another problem:
<?php
$fp = fopen ('/path/to/file', "r");
while (!feof ($fp))
{
$value = fgets($fp);
if(!empty($value))
{
//Here do what you want with your value
}
}
?>
This was string-by-string reading code. Also you can use file_get_contents(); php-function and work with it lika string.
P.S> Sorry for my english