Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Copy function works but only with literals
Old 12-28-2010, 10:00 AM Copy function works but only with literals
Junior Talker

Posts: 3
Name: ron
Trades: 0
I tried searching the forum but cant find an answer to using variables in a copy(src,dst) function on a live hosted unix website.

I have php code in a folder /userforms and audio files in folders

/userforms/files/ and
/userforms/files/path1/

if I write a php literal test and put it in /userforms/ as follows


<?php
copy("./files/haha.txt","./files/path1/haha.txt");

copy('./files/1293437254.mp3','./files/path1/1293437254.mp3');

then it works OK

But if I write it thus... echoing the variables with _,_ seperating them
for clarity in the echo statement only


$src= "./files";
$dst= "./files/path1/";

$mysrc = "'". $src . $usr_filename ."'" ;
$mydst = "'". $dst . $usr_filename ."'";

echo $mysrc ." _,_ ". $mydst;

copy( $mysrc , $mydst);

then I get displayed


'./files/1293437254.mp3' _,_ './files/path1/1293437254.mp3'

Warning: copy('./files/1293437254.mp3') [function.copy]: failed to open stream: No such file or directory in /home/mysite/public_html/jackson/userforms/upd_file.php on line 70



I have tried with site path (my www.website) as
/home/mysite/public_html/jackson/userforms/files/

but same result
videocen is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-28-2010, 10:07 AM Re: Copy function works but only with literals
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Why are you concatenating quotes to the source and destination vars? Try:
PHP Code:
$src"./files";
$dst"./files/path1/";
$mysrc $src $usr_filename
$mydst $dst $usr_filename;
echo 
$mysrc ." _,_ "$mydst;

copy$mysrc $mydst); 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 12-28-2010, 11:01 AM Re: Copy function works but only with literals
Junior Talker

Posts: 3
Name: ron
Trades: 0
Yes correct - better php coding, but same result.

The question is - Why literals work and variables dont ?

result with your code as follows

./files1293437254.mp3 _,_ ./files/path1/1293437254.mp3
Warning: copy(./files1293437254.mp3) [
function.copy]: failed to open stream: No such file or directory in /home/mysite/public_html/jackson/userforms/upd_file.php on line 82


videocen is offline
Reply With Quote
View Public Profile
 
Old 12-28-2010, 11:31 AM Re: Copy function works but only with literals
Junior Talker

Posts: 3
Name: ron
Trades: 0
When in doubt try another file.

In the time I was testing, the database containing the filenames was not updated. Another program, Express Scribe had downloaded and deleted the file. (the full web app distributes files to users and they download using Express Scribe)

Also exposes another web tester flaw, humans often keep testing with the same filename, assuming its still there. This copy function is being added to split files into specific folders when assigned to users because Express Scribe downloads all the files it finds .

My humbles appologies - bugfix done.
videocen is offline
Reply With Quote
View Public Profile
 
Old 12-28-2010, 11:55 AM Re: Copy function works but only with literals
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by videocen View Post
Yes correct - better php coding, but same result.
I'm pretty sure that it is not just a matter of better or worse code. With quotes it won't be a valid filename.

I just tested this:
PHP Code:
echo (int) file_exists('\'somefile.php\''); //outputs 0

echo (int) file_exists('somefile.php'); //outputs 1 
Anyways... glad to see you got it fixed.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 12-28-2010, 01:43 PM Re: Copy function works but only with literals
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
You need to add a directory seperator to the end of the path:

$src = "./files/";
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Copy function works but only with literals
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25308 seconds with 12 queries