Hi,
I am using the following copy code to move all files from 1 folder to another but i always get an error....can someone please tell me where i am going wrong with this piece of coding.
here is the code: - <?
-
copy($tempFLDR, $path) or die ;
-
?>
here is the error message:
Warning: copy(upload/imgtemp/1369012657/IMG00038.jpg) [function.copy]: failed to open stream: No such file or directory in /home/vecre0/public_html/test/8/addimgck.php on line 86
19 2509 @anfetienne
Considering the error complains about "No such file or directory", I would be inclined to ask:
1. Does the .jpg file exist at the path shown.
2. Does the destination path (in the $path variable) exist?
Regards,
Jeff
yes it does exist.....the file names are
1b.jpg
2b.jpg
3b.jpg etc etc and the location does exist. All the files upload perfectly fine but it just wont copy over
@anfetienne
To tell you the truth, we are going to have to see the actual code you are using because that error says different. Can you post it here please?
Regards,
Jeff
IMG00038.jpg is not the same as 1b.jpg. There's not enough detail here for us to give you an answer. What does $tempFLDR contain? The name suggests it's a folder.. What does $path contain? Again, the name suggests a path to a directory not a file.
here is the full coding to the file -
<!doctype html public "-//w3c//dtd html 3.2//en">
-
<html>
-
<head>
-
<title>Multiple image upload script from plus2net.com</title>
-
</head>
-
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
-
<?
-
-
$random_digit = $_POST['ID'];
-
$returnURL = $_POST['returnURL'];
-
-
$imgtemp=mkdir("upload/imgtemp/$random_digit", 0777);
-
-
-
?>
-
-
-
-
<?
-
while(list($key,$value) = each($_FILES['images']['name']))
-
{
-
if(!empty($value))
-
{
-
$filename = $value;
-
$filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
-
-
$add = "upload/$random_digit/$filename";
-
$tempFLDR = "upload/imgtemp/$random_digit/$filename";
-
//echo $_FILES['images']['type'][$key];
-
// echo "<br>";
-
copy($_FILES['images']['tmp_name'][$key], $add);
-
chmod("$add",0777);
-
copy($_FILES['images']['tmp_name'][$key], $tempFLDR);
-
chmod("$tempFLDR",0777);
-
-
$folderPath="upload/$random_digit/";
-
}
-
}
-
?>
-
-
<?
-
//fill in details about the path
-
$path="upload/$random_digit/";
-
-
//variable used for the name of each file
-
$i=1;
-
-
$od = opendir($path);
-
while (false !== ($filename = readdir($od)))
-
{
-
//you can add any type of filenames you wish to skip (for instance Thumbs.db on windows)
-
if($filename != '.' && $filename != '..' && !is_dir($path.$filename))
-
{
-
//we give files a name - here we use increasing numbers for jpg files:
-
if(rename($path.$filename, $path.$i++.'.jpg'))
-
echo 'Renamed file '.$filename.'<br />';
-
}
-
}
-
-
closedir($od);
-
-
?>
-
-
<?
-
//fill in details about the path
-
$pathT="upload/imgtemp/$random_digit/";
-
-
//variable used for the name of each file
-
$i=1;
-
-
$odT = opendir($pathT);
-
while (false !== ($filename = readdir($odT)))
-
{
-
//you can add any type of filenames you wish to skip (for instance Thumbs.db on windows)
-
if($filename != '.' && $filename != '..' && !is_dir($pathT.$filename))
-
{
-
//we give files a name - here we use increasing numbers for jpg files:
-
if(rename($pathT.$filename, $pathT.$i++.'b.jpg'))
-
echo 'Renamed file '.$filename.'<br />';
-
}
-
}
-
closedir($odT);
-
?>
-
-
<?
-
copy($tempFLDR, $path) or die ;
-
?>
-
<?
-
$username="vecre0_tempU";
-
$password="auction";
-
$database="vecre0_templates";
-
-
-
// OPEN CONNECTION --->
-
$connection=mysql_connect("localhost","$username", "$password") or die("Unable to connect!");
-
-
mysql_select_db("$database") or die("Unable to select database!");
-
-
-
// EXECUTE QUERY --->
-
$query="INSERT INTO paths (
-
-
folderPath)
-
-
VALUES(
-
'".$folderPath."')";
-
//////----->
-
$result=mysql_query($query) or die("Error in query:".mysql_error());
-
//if ($result)
-
//echo mysql_affected_rows()." row inserted into the database effectively.";
-
-
// CLOSE CONNECTION --->
-
mysql_close($connection);
-
?>
-
-
-
-
-
-
-
</body>
-
-
</html>
-
$path does not point to a file. It points to a folder. It's hard to help me help you because I have no clue what is happening in your code. There doesn't seem to be any logic to it. Looks like you do things more than necessary.
If you could explain what you want to happen, we may be able to help you rewrite it.
the code below brings in the (ID) random_digit from a previous page and the return url. it creates the temp folder using the random_digit as its end.
it creates the main folder for the random_digit and uploads the images to the main folder.....it then copies them to the temp folder. $folderPath is used only for the sql db. -
<?
-
-
$random_digit = $_POST['ID'];
-
$returnURL = $_POST['returnURL'];
-
-
$imgtemp=mkdir("upload/imgtemp/$random_digit", 0777);
-
-
-
?>
-
-
-
-
<?
-
while(list($key,$value) = each($_FILES['images']['name']))
-
{
-
if(!empty($value))
-
{
-
$filename = $value;
-
$filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
-
-
$add = "upload/$random_digit/$filename";
-
$tempFLDR = "upload/imgtemp/$random_digit/$filename";
-
//echo $_FILES['images']['type'][$key];
-
// echo "<br>";
-
copy($_FILES['images']['tmp_name'][$key], $add);
-
chmod("$add",0777);
-
copy($_FILES['images']['tmp_name'][$key], $tempFLDR);
-
chmod("$tempFLDR",0777);
-
-
$folderPath="upload/$random_digit/";
-
}
-
}
-
?>
-
the code below opens up the main folder and renames the images within by incrementing them i.e. 1.jpg, 2.jpg, 3.jpg etc
then in the 2nd part the temp folder is then opens up and all images within are renamed by incrementing them but as these are for thumbnails they are renamed to 1b.jpg, 2b.jpg, 3b.jpg etc -
<?
-
//fill in details about the path
-
$path="upload/$random_digit/";
-
-
//variable used for the name of each file
-
$i=1;
-
-
$od = opendir($path);
-
while (false !== ($filename = readdir($od)))
-
{
-
//you can add any type of filenames you wish to skip (for instance Thumbs.db on windows)
-
if($filename != '.' && $filename != '..' && !is_dir($path.$filename))
-
{
-
//we give files a name - here we use increasing numbers for jpg files:
-
if(rename($path.$filename, $path.$i++.'.jpg'))
-
echo 'Renamed file '.$filename.'<br />';
-
}
-
}
-
-
closedir($od);
-
-
?>
-
-
<?
-
//fill in details about the path
-
$pathT="upload/imgtemp/$random_digit/";
-
-
//variable used for the name of each file
-
$i=1;
-
-
$odT = opendir($pathT);
-
while (false !== ($filename = readdir($odT)))
-
{
-
//you can add any type of filenames you wish to skip (for instance Thumbs.db on windows)
-
if($filename != '.' && $filename != '..' && !is_dir($pathT.$filename))
-
{
-
//we give files a name - here we use increasing numbers for jpg files:
-
if(rename($pathT.$filename, $pathT.$i++.'b.jpg'))
-
echo 'Renamed file '.$filename.'<br />';
-
}
-
}
-
closedir($odT);
-
?>
-
after this id just want to resize the images within the temp folder and copy them back to the main folder. once copied the temp folder for that ID will be deleted. The only problem i have is resizing them and copying them. I haven't tried to resize them as yet but from what you are saying i need $path ending with $filename instead of just pointing to a directory
everything in my coding works perfectly fine its just copying the files back to the main folder from the temp folder that is my main issue at this point....i have not tried any resizing codes just yet
@anfetienne
Here is one discrepancy that I see. On line 15 you have the following code to rename the files: -
if(rename($path.$filename, $path.$i++.'.jpg'))
-
and as you say, you are naming the files 1b.jpg, 2b.jpg, etc. Yet in this rename step, there is no "b" following the "i++", so your files would be called 1.jpg, 2.jpg, etc.
Below all that though, you again do a rename with the following code: -
if(rename($pathT.$filename, $pathT.$i++.'b.jpg'))
-
Are you needing to rename files twice? I have to agree with markus that you are doing a lot here and possibly too much. It feels like you are going 10 miles when you only need to go several hundred feet.
Regards,
Jeff
if you look clearly they relate to 2 different directories......the 1st with $path is for the main folder....that renames the files to 1.jpg, 2.jpg, 3.jpg etc
the 2nd with $pathT is for the thumbnails that need creating...that renames them to 1b.jpg, 2b.jpg, 3b.jpg etc....these to coding run for two different directories
if i could have one code to do everything i need i would but it's impossible ive spent weeks researching how to do it and this is the only way that works.
But i am still working on it and i'm very close to getting the code right.
I still can't make sense of the code.
Why are you creating a temp directory? In case you didn't know, when you upload files ($_FILES array) they are stored temporarily in a predefined directory. You then have access to the files via $_FILES['file']['tmp_name']. Creating a new directory to temporarily store these images is pointless.
if i could have one code to do everything i need i would but it's impossible ive spent weeks researching how to do it and this is the only way that works.
You can do it all at once.
So, here's what you're (trying) to accomplish (as I see it): - Generating a directory (randomly named),
- Moving the uploaded files to that folder,
- and then creating a thumbnail of the file.
Is that correct? I'm sure we could lighten this could up and make it follow a logical path.
- Markus.
yes that is exactly what im trying to do
Here is what I have put together: -
/*
-
A little programming tip:
-
1. Stick to just 1 naming convention. You shift between
-
using underscores and camelCase. Using one will eventually
-
make it easier to read for you (and others, i.e. me and numberwhun).
-
2. Document your code! Make comments for just about everything -
-
it'll help you (and others) a bunch in the future!
-
*/
-
-
// Turn error reporting on!
-
error_reporting(E_ALL);
-
-
// Our random digit, used as the directory name - checks for post data.
-
$random_digit = ( isset ( $_POST['ID'] ) ) ? $_POST['ID'] : rand();
-
// Return URL - presumably for when the script ends? - checks for post data.
-
$return_url = ( isset ( $_POST['returnURL'] ) ) ? $_POST['returnURL'] : "?error";
-
// Now let's set the path to the 'uploads/<random_digit>' dir - no trailing slash.
-
$upload_path = "upload/{$random_digit}";
-
// And the upload path for the thumbnails dir.
-
$upload_path_t = $upload_path . "/t/";
-
// Try to create the directorys.
-
if ( mkdir( $upload_path, 0777 ) && mkdir( $upload_path_t, 0777 ) )
-
{
-
// Directorys made successfully.
-
// Now traverse the FILES array, adding one file to the
-
// $upload_path dir, and one to the $upload_path_t (thumbnail) dir.
-
foreach( $_FILES['files'] as $key => $file )
-
{
-
// Check for errors
-
if ( $file['error'] == 0 )
-
{
-
// Make sure it's been uploaded through PHP.
-
if ( is_uploaded_file ( $file['tmp_name'] ) )
-
{
-
// Move files to directorys.
-
if ( move_uploaded_file( $file['tmp_name'], $upload_path ) &&
-
move_uploaded_file( $file['tmp_name'], $upload_path_t ) )
-
{
-
echo "Files successfully uploaded. key: {$key}";
-
}
-
// File not moved.
-
else
-
{
-
echo "Problem moving files. key: {$key}";
-
}
-
}
-
// Not uploaded file.
-
else
-
{
-
echo "Files not uploaded through PHP. key: {$key}";
-
}
-
}
-
// Error with file.
-
else
-
{
-
echo "File errorno: {$file['error']}. key: {$key}";
-
}
-
}
-
}
-
// Directory not made.
-
else
-
{
-
echo "Problem making dirs.";
-
}
You may have to make changes to it (the paths, etc). Instead of putting the thumbnails and originals in the same directory, separate them - makes things a lot easier.
The flow of the above is: - Create the directories (orig, and thumbnail),
- traverse the files using a foreach() loop,
- check the file for errors,
- check the file was uploaded through php,
- and then eventually attempt to move the files.
Hope this helps - I threw it together without testing it, so there may be some errors. Let us know.
- Markus.
can you tell me a way i can copy the thumbnails from the /t/ folder back to the main folder.....images are renamed so there is no need to keep them seperate.
@anfetienne
The best practice is to keep them separate. Having them all in the same place is messy and unorganized.
Hi Markus,
I have changed a lil piece of my coding and i have got the code to make two temporary folders, upload the images, rename them and move them to the main folder.
These images are used for a flash gallery that i bought. it is already coded to read the images as:
1.jpg (the main image)
1b.jpg (the thumbnail) etc etc
so saving me time in changing that coding as well my aim was to make php adapt to what i bought and i've achieved that with your help thanks a lot
@anfetienne
I still don't understand why you're using temporary folders, when you really don't have to. But, nevermind. @anfetienne
Ok, that makes sense.
Glad we could be of some help,
Mark.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mike |
last post by:
I want to be able to copy a directory of files (all .HTM files) from a
network drive to a local drive on the machine c:\HTMFiles , How can i do
that?
I tried File.Copy(source, dest) but i need...
|
by: Wayne Wengert |
last post by:
I am using VSNET 2003 to build an ASP.NET/VB set of pages. There are
currently about a dozen aspx pages. When I make even a minor change to one
page I currently rebuild the solution, copy the...
|
by: Johnny |
last post by:
Hi,
I have created an ASP.NET application (let's call it FooBar) with VS.NET on
my local machine, residing in http://localhost/FooBar. Deploying it to
another folder on my machine works well...
|
by: Steve Franks |
last post by:
The Copy Web tool provided with VS.NET 2005 is very convenient. However
every once in a while it seems to think the files on the remote server have
changed, which they have not. Then when I use...
|
by: DraguVaso |
last post by:
Hi,
I'm looking for a way to Copy and Paste Files to the clipboard.
I found a lot of articles to copy pieces of text and bitmaps etc, but nog
whole files.
Whay I need is like you have in...
|
by: luis molina Micasoft |
last post by:
it seems that when i do file.copy the svchost.exe is hanged, i mean if i make
40 threads of file.copy , 40 copys of files at same time the system is going
down and stop responding, this is when i'm...
|
by: dkmarni |
last post by:
Hi,
I am trying to do this perl script, but not able to complete it successfully.
Here is the description what the script has to do..
Accept two and only two command line arguments. Again,...
|
by: jim |
last post by:
Is there a way (using VB.Net or C#) to copy open or locked files?
Thanks!
jim
|
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= |
last post by:
Using .NET 2.0 is it more efficient to copy files to a single folder versus
spreading them across multiple folders.
For instance if we have 100,000 files to be copied,
Do we copy all of them to...
|
by: =?Utf-8?B?UmFkZW5rb19aZWM=?= |
last post by:
I am using standard File.Copy(source,dest,true) method in C# and I have
problem with copying large number of files.
Here is my code:
foreach (FileInfo file in files)
{...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |